{"id":232792,"date":"2023-01-29T10:36:00","date_gmt":"2023-01-29T07:36:00","guid":{"rendered":"https:\/\/wordpress.mediadoma.com\/?p=232792"},"modified":"2023-01-29T10:36:27","modified_gmt":"2023-01-29T07:36:27","slug":"jak-nalashtuvati-scenarij-php-u-crontab-dlja-ochishhennja-kilkoh-wordpress-baz-danih-na-odnomu-serveri","status":"publish","type":"post","link":"https:\/\/wordpress.mediadoma.com\/uk\/jak-nalashtuvati-scenarij-php-u-crontab-dlja-ochishhennja-kilkoh-wordpress-baz-danih-na-odnomu-serveri\/","title":{"rendered":"\u042f\u043a \u043d\u0430\u043b\u0430\u0448\u0442\u0443\u0432\u0430\u0442\u0438 \u0441\u0446\u0435\u043d\u0430\u0440\u0456\u0439 PHP \u0443 Crontab \u0434\u043b\u044f \u043e\u0447\u0438\u0449\u0435\u043d\u043d\u044f \u043a\u0456\u043b\u044c\u043a\u043e\u0445 WordPress (\u0431\u0430\u0437 \u0434\u0430\u043d\u0438\u0445) \u043d\u0430 \u043e\u0434\u043d\u043e\u043c\u0443 \u0441\u0435\u0440\u0432\u0435\u0440\u0456?"},"content":{"rendered":"<p>\u042f\u043a\u0449\u043e \u0432\u0438 \u0440\u043e\u0437\u043c\u0456\u0449\u0443\u0454\u0442\u0435 \u0431\u0430\u0433\u0430\u0442\u043e \u0431\u043b\u043e\u0433\u0456\u0432 WordPress \u043d\u0430 \u043e\u0434\u043d\u043e\u043c\u0443 \u0441\u0435\u0440\u0432\u0435\u0440\u0456, \u0432\u0438 \u043c\u043e\u0436\u0435\u0442\u0435 \u043b\u0435\u0433\u043a\u043e \u0437\u0440\u043e\u0431\u0438\u0442\u0438 \u0446\u0435 \u0437\u0430 \u0434\u043e\u043f\u043e\u043c\u043e\u0433\u043e\u044e \u043d\u0430\u0441\u0442\u0443\u043f\u043d\u043e\u0433\u043e \u0441\u0446\u0435\u043d\u0430\u0440\u0456\u044e PHP. \u042f \u0440\u043e\u0437\u043c\u0456\u0441\u0442\u0438\u0432 6 \u0432\u0435\u0431-\u0441\u0430\u0439\u0442\u0456\u0432 \u043d\u0430 \u043e\u0434\u043d\u043e\u043c\u0443 <a href=\"https:\/\/helloacm.com\/the-ultimate-vps-from-quickhostuk\/\" target=\"_blank\" rel=\"noopener nofollow\" class=\"external external_icon\">VPS<\/a>, \u0442\u043e\u043c\u0443 \u0437\u0430\u043c\u0456\u0441\u0442\u044c \u0442\u043e\u0433\u043e, \u0449\u043e\u0431 \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0442\u0438 \u0441\u0446\u0435\u043d\u0430\u0440\u0456\u0439 \u043e\u0447\u0438\u0449\u0435\u043d\u043d\u044f \u043e\u0434\u0438\u043d \u0437\u0430 \u043e\u0434\u043d\u0438\u043c, \u044f \u043c\u043e\u0436\u0443 \u043f\u0440\u043e\u0441\u0442\u043e \u043f\u043e\u043c\u0456\u0441\u0442\u0438\u0442\u0438 \u0439\u043e\u0433\u043e \u0432 <a href=\"https:\/\/helloacm.com\/crontab-generator-secure-fast-handy-tool-to-generate-the-crontab-lines\/\" target=\"_blank\" rel=\"noopener nofollow\" class=\"external external_icon\">crontab<\/a>, \u0449\u043e\u0431 \u043c\u0435\u043d\u0456 \u0431\u0443\u043b\u043e \u043b\u0435\u0433\u0448\u0435.<\/p>\n<p>\u041f\u043e-\u043f\u0435\u0440\u0448\u0435, \u0432\u0430\u043c \u0437\u043d\u0430\u0434\u043e\u0431\u0438\u0442\u044c\u0441\u044f \u0449\u043e\u0441\u044c \u043f\u043e\u0434\u0456\u0431\u043d\u0435 (\u0437\u0440\u0443\u0447\u043d\u0456 \u0444\u0443\u043d\u043a\u0446\u0456\u0457).<\/p>\n<pre><code>\u00a0 set_time_limit(600);\n\u00a0 mysql_connect(\"localhost\", \"user\", \"password\") or die(mysql_error());\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \n\u00a0 function run_query($query) {\n\u00a0 \u00a0 echo $query;\n\u00a0 \u00a0 mysql_query($query) or die(mysql_error());\n\u00a0 \u00a0 echo \" ***OK!*** n\";\n\u00a0 } \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 <\/code><\/pre>\n<p>Set_time_limit <strong>(600)<\/strong> \u0454 \u043b\u0438\u0448\u0435 \u0437\u0430\u043f\u043e\u0431\u0456\u0436\u043d\u0438\u043c \u0437\u0430\u0445\u043e\u0434\u043e\u043c \u043d\u0430 \u0432\u0438\u043f\u0430\u0434\u043e\u043a, \u044f\u043a\u0449\u043e \u0432\u0456\u043d \u0437\u0430\u0432\u0438\u0441\u0430\u0454 (\u0449\u043e\u0431 \u0432\u0438 \u043c\u043e\u0433\u043b\u0438 \u0431\u0435\u0437\u043f\u0435\u0447\u043d\u043e \u043f\u043e\u043c\u0456\u0441\u0442\u0438\u0442\u0438 \u0446\u0435 \u0432 <a href=\"https:\/\/helloacm.com\/crontab-generator-secure-fast-handy-tool-to-generate-the-crontab-lines\/\" target=\"_blank\" rel=\"noopener nofollow\" class=\"external external_icon\">crontab<\/a> ). \u041e\u0431\u043e\u0432&#8217;\u044f\u0437\u043a\u043e\u0432\u043e \u0437\u0430\u043c\u0456\u043d\u0456\u0442\u044c \u0434\u0430\u043d\u0456 \u0434\u043e\u0441\u0442\u0443\u043f\u0443 \u0434\u043e mysql. \u0424\u0443\u043d\u043a\u0446\u0456\u044f <strong>run_query()<\/strong> \u043d\u0430\u0434\u0440\u0443\u043a\u0443\u0454 \u0437\u0430\u043f\u0438\u0442 \u0456 \u0432\u0438\u043a\u043e\u043d\u0430\u0454 \u0439\u043e\u0433\u043e, \u044f\u043a\u0449\u043e \u0449\u043e\u0441\u044c \u043f\u0456\u0434\u0435 \u043d\u0435 \u0442\u0430\u043a, \u0437\u0430\u0433\u0430\u043b\u044c\u043d\u0438\u0439 \u0441\u0446\u0435\u043d\u0430\u0440\u0456\u0439 \u0437\u0430\u0432\u0435\u0440\u0448\u0438\u0442\u044c\u0441\u044f.<\/p>\n<p>\u0422\u0435\u043f\u0435\u0440 \u0446\u0435 \u043d\u0430\u0439\u043a\u0440\u0430\u0449\u0430 \u0447\u0430\u0441\u0442\u0438\u043d\u0430, \u0432\u0438 \u043c\u043e\u0436\u0435\u0442\u0435 \u043e\u0431\u2019\u0454\u0434\u043d\u0430\u0442\u0438 \u043a\u0456\u043b\u044c\u043a\u0430 \u0434\u043e\u0431\u0440\u0435 \u0432\u0456\u0434\u043e\u043c\u0438\u0445 \u0456 \u0432\u0438\u043a\u043e\u0440\u0438\u0441\u0442\u043e\u0432\u0443\u0432\u0430\u043d\u0438\u0445 SQL-\u0437\u0430\u043f\u0438\u0442\u0456\u0432, \u0449\u043e\u0431 \u043c\u043e\u0436\u043d\u0430 \u0431\u0443\u043b\u043e \u0432\u0438\u043a\u043e\u043d\u0430\u0442\u0438 \u0432\u0441\u0456 \u043e\u0434\u043d\u043e\u0447\u0430\u0441\u043d\u043e.<\/p>\n<pre><code>\u00a0 function clean_wp($db_name, $table_prefix, $skipwp = false) {\n\u00a0 \u00a0 mysql_select_db($db_name);\n\u00a0\n\u00a0 \u00a0 echo \"Optimising $db_name... n\";\n\u00a0 \u00a0 \n\u00a0 \u00a0 if (!$skipwp) {\n\u00a0 \u00a0 \u00a0 $query = \"\n \u00a0 \u00a0 \u00a0 \u00a0DELETE `a`, `b`, `c` FROM `{$table_prefix}terms` AS `a` \n \u00a0 \u00a0 \u00a0 \u00a0LEFT JOIN `{$table_prefix}term_taxonomy` AS `c` ON `a`.`term_id` = `c`.`term_id` \n \u00a0 \u00a0 \u00a0 \u00a0LEFT JOIN `{$table_prefix}term_relationships` AS `b` ON `b`.`term_taxonomy_id` = `c`.`term_taxonomy_id` \n \u00a0 \u00a0 \u00a0 \u00a0WHERE `c`.`taxonomy` = 'post_tag' AND `c`.`count` = 0\";\n\u00a0 \n\u00a0 \u00a0 \u00a0 run_query($query);\n\u00a0 \u00a0 \u00a0 \n\u00a0 \u00a0 \u00a0 $query = \"\n \u00a0 \u00a0 \u00a0 \u00a0DELETE `a`, `b`, `c`\n \u00a0 \u00a0 \u00a0 \u00a0FROM `{$table_prefix}posts` as `a`\n \u00a0 \u00a0 \u00a0 \u00a0LEFT JOIN `{$table_prefix}term_relationships` as `b` ON (`a`. `ID` = `b`. `object_id`) \u00a0 \u00a0 \u00a0 \u00a0LEFT JOIN `{$table_prefix}postmeta` as `c` ON (`a`. `ID` = `c`. `post_id`) \u00a0 \u00a0 \u00a0 \u00a0WHERE `a`. `post_type` = 'revision' \n \u00a0 \u00a0 \u00a0\";\n\u00a0 \n\u00a0 \u00a0 \u00a0 run_query($query);\n\u00a0 \u00a0 \u00a0 \u00a0 \n\u00a0 \u00a0 \u00a0 $query = \"\n \u00a0 \u00a0 \u00a0 \u00a0DELETE FROM `{$table_prefix}commentmeta`\n \u00a0 \u00a0 \u00a0 \u00a0WHERE `comment_id` NOT IN (\u00a0 \u00a0 \u00a0 \u00a0 \u00a0SELECT `comment_id`\n \u00a0 \u00a0 \u00a0 \u00a0 \u00a0FROM `{$table_prefix}comments` \n \u00a0 \u00a0 \u00a0 \u00a0)\n \u00a0 \u00a0 \u00a0\";\n\u00a0 \u00a0 \u00a0 \u00a0 \n\u00a0 \u00a0 \u00a0 run_query($query);\n\u00a0 \n\u00a0 \u00a0 \u00a0 $query = \"\n \u00a0 \u00a0 \u00a0 \u00a0DELETE FROM `{$table_prefix}commentmeta` \n \u00a0 \u00a0 \u00a0 \u00a0WHERE `meta_key` LIKE \"%akismet%\"\n \u00a0 \u00a0 \u00a0\";\n\u00a0 \u00a0 \u00a0 \u00a0 \n\u00a0 \u00a0 \u00a0 run_query($query); \u00a0\n\u00a0 \n\u00a0 \u00a0 \u00a0 $query = \"\n \u00a0 \u00a0 \u00a0 \u00a0DELETE FROM `{$table_prefix}comments` \n \u00a0 \u00a0 \u00a0 \u00a0WHERE `comment_approved` &lt;&gt; 1\n \u00a0 \u00a0 \u00a0\";\n\u00a0 \u00a0 \u00a0 \n\u00a0 \u00a0 \u00a0 run_query($query);\n\u00a0 \u00a0 \u00a0 \n\u00a0 \u00a0 \u00a0 $query = \"\n \u00a0 \u00a0 \u00a0 \u00a0DELETE FROM `{$table_prefix}posts` \n \u00a0 \u00a0 \u00a0 \u00a0WHERE `post_type` = \"revision\"\n \u00a0 \u00a0 \u00a0\";\n\u00a0 \n\u00a0 \u00a0 \u00a0 run_query($query);\n\u00a0 \u00a0 }\n\u00a0\n\u00a0 \u00a0 $alletabellen = mysql_query(\"SHOW TABLES\");\n\u00a0\n\u00a0 \u00a0 while($tabel = mysql_fetch_assoc($alletabellen))\n\u00a0 \u00a0 {\n\u00a0 \u00a0 \u00a0 \u00a0 foreach ($tabel as $db =&gt; $tabelnaam) \n\u00a0 \u00a0 \u00a0 \u00a0 {\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 $query = \"REPAIR TABLE `$tabelnaam`\";\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 run_query($query);\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 $query = \"OPTIMIZE TABLE `$tabelnaam`\";\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 run_query($query);\n\u00a0 \u00a0 \u00a0 \u00a0 }\n\u00a0 \u00a0 }\n\u00a0 \u00a0 \n\u00a0 \u00a0 echo \" --- Done!!! ---\";\n\u00a0 }<\/code><\/pre>\n<p>\u0424\u0443\u043d\u043a\u0446\u0456\u044f <strong>clean_wp<\/strong> \u043f\u0440\u0438\u0439\u043c\u0430\u0454 3 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0438. \u041f\u0435\u0440\u0448\u0435 \u2014 \u0446\u0435 \u0456\u043c\u2019\u044f \u0442\u0430\u0431\u043b\u0438\u0446\u0456 (\u0442\u043e\u0431\u0442\u043e \u0432\u0438 \u043c\u043e\u0436\u0435\u0442\u0435 \u043f\u0435\u0440\u0435\u0434\u0430\u0442\u0438 \u0440\u0456\u0437\u043d\u0456 \u0442\u0430\u0431\u043b\u0438\u0446\u0456 \u0434\u043b\u044f \u0440\u0456\u0437\u043d\u0438\u0445 \u0431\u043b\u043e\u0433\u0456\u0432 WordPress). \u0414\u0440\u0443\u0433\u0438\u0439 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440 \u0432\u0438\u0437\u043d\u0430\u0447\u0430\u0454 \u043f\u0440\u0435\u0444\u0456\u043a\u0441 \u0442\u0430\u0431\u043b\u0438\u0446\u0456 wp, \u0430 \u0437\u0430 \u0437\u0430\u043c\u043e\u0432\u0447\u0443\u0432\u0430\u043d\u043d\u044f\u043c \u043c\u0430\u0454 \u0431\u0443\u0442\u0438 wp_. \u0422\u0440\u0435\u0442\u0456\u0439 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440 \u0432\u0438\u0437\u043d\u0430\u0447\u0430\u0454, \u0447\u0438 \u0454 \u0432 \u0446\u0456\u0439 \u0442\u0430\u0431\u043b\u0438\u0446\u0456 \u0431\u043b\u043e\u0433 wordpress, \u0442\u043e\u0436 \u0432\u0438 \u043c\u043e\u0436\u0435\u0442\u0435 \u0456\u0433\u043d\u043e\u0440\u0443\u0432\u0430\u0442\u0438 \u0437\u0430\u043f\u0438\u0442\u0438 \u043d\u0430 \u043e\u0447\u0438\u0449\u0435\u043d\u043d\u044f, \u043f\u043e\u0432\u2019\u044f\u0437\u0430\u043d\u0456 \u0437 wordpress, \u0456 \u0432\u0438\u043a\u043e\u043d\u0443\u0432\u0430\u0442\u0438 \u043b\u0438\u0448\u0435 \u0437\u0430\u0433\u0430\u043b\u044c\u043d\u0456.<\/p>\n<p>\u0417\u0430\u043f\u0438\u0442\u0438 <a href=\"https:\/\/helloacm.com\/sql-coding-exercise-delete-duplicate-emails\/\" target=\"_blank\" rel=\"noopener nofollow\" class=\"external external_icon\">SQL<\/a> \u043f\u0440\u0438\u0437\u043d\u0430\u0447\u0435\u043d\u0456 \u0434\u043b\u044f \u043e\u0447\u0438\u0449\u0435\u043d\u043d\u044f \u043a\u043e\u0448\u0438\u043a\u0430 \u043a\u043e\u043c\u0435\u043d\u0442\u0430\u0440\u0456\u0432, \u043d\u0435\u0437\u0430\u0442\u0432\u0435\u0440\u0434\u0436\u0435\u043d\u0438\u0445 \u043a\u043e\u043c\u0435\u043d\u0442\u0430\u0440\u0456\u0432 (\u0431\u0443\u0434\u044c\u0442\u0435 \u043e\u0431\u0435\u0440\u0435\u0436\u043d\u0456 \u0437 \u0446\u0438\u043c), <a href=\"https:\/\/wordpress.mediadoma.com\/uk\/skorochennja-vikoristannja-bazi-danih-wordpress\/\" title=\"\u0432\u0435\u0440\u0441\u0456\u0439\">\u0432\u0435\u0440\u0441\u0456\u0439<\/a>. \u0417\u0430\u0433\u0430\u043b\u044c\u043d\u0456 \u0437\u0430\u043f\u0438\u0442\u0438 \u0432\u043a\u043b\u044e\u0447\u0430\u044e\u0442\u044c \u043e\u043f\u0442\u0438\u043c\u0456\u0437\u0430\u0446\u0456\u044e \u0442\u0430 \u0440\u0435\u043c\u043e\u043d\u0442. \u0422\u043e\u0436 \u0432\u0438 \u0437\u043c\u043e\u0436\u0435\u0442\u0435 \u043b\u0435\u0433\u043a\u043e \u043f\u043e\u043c\u0456\u0441\u0442\u0438\u0442\u0438 \u0446\u0435 \u0432 <a href=\"https:\/\/helloacm.com\/how-to-set-up-email-when-your-server-reboots-using-crontab-and-mail\/\" target=\"_blank\" rel=\"noopener nofollow\" class=\"external external_icon\">crontab<\/a>.<\/p>\n<p><div id=\"PostUnique_PostSource\" style=\"padding-top: 50px\">\u0414\u0436\u0435\u0440\u0435\u043b\u043e \u0437\u0430\u043f\u0438\u0441\u0443:  <a target=\"_blank\" rel=\"noopener nofollow\" href=\"\/\/helloacm.com\" class=\"external external_icon\">helloacm.com<\/a><\/div><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u042f\u043a \u043d\u0430\u043b\u0430\u0448\u0442\u0443\u0432\u0430\u0442\u0438 PHP-\u0441\u043a\u0440\u0438\u043f\u0442 \u0443 Crontab \u0434\u043b\u044f \u043e\u0447\u0438\u0449\u0435\u043d\u043d\u044f \u043a\u0456\u043b\u044c\u043a\u043e\u0445 WordPress (\u0431\u0430\u0437 \u0434\u0430\u043d\u0438\u0445) \u043d\u0430 \u043e\u0434\u043d\u043e\u043c\u0443 \u0441\u0435\u0440\u0432\u0435\u0440\u0456?<\/p>\n","protected":false},"author":1,"featured_media":224680,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":"","_wp_rev_ctl_limit":""},"categories":[808,869,839,902,849,725],"tags":[1174],"class_list":["post-232792","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-php-10","category-wordpress-10","category-kerivnytstvo-dlia-pochatkivtsiv","category-kod-3","category-pidruchnyky","category-rozrobnyk","tag-affiai-uk"],"_links":{"self":[{"href":"https:\/\/wordpress.mediadoma.com\/uk\/wp-json\/wp\/v2\/posts\/232792","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/wordpress.mediadoma.com\/uk\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/wordpress.mediadoma.com\/uk\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/wordpress.mediadoma.com\/uk\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/wordpress.mediadoma.com\/uk\/wp-json\/wp\/v2\/comments?post=232792"}],"version-history":[{"count":0,"href":"https:\/\/wordpress.mediadoma.com\/uk\/wp-json\/wp\/v2\/posts\/232792\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/wordpress.mediadoma.com\/uk\/wp-json\/wp\/v2\/media\/224680"}],"wp:attachment":[{"href":"https:\/\/wordpress.mediadoma.com\/uk\/wp-json\/wp\/v2\/media?parent=232792"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/wordpress.mediadoma.com\/uk\/wp-json\/wp\/v2\/categories?post=232792"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/wordpress.mediadoma.com\/uk\/wp-json\/wp\/v2\/tags?post=232792"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}