KNOWNHOST WIKI

User Tools

Site Tools


cms:wordpress:cron-convert

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
cms:wordpress:cron-convert [2019/10/10 13:31]
Karson N.
cms:wordpress:cron-convert [2020/06/10 13:38] (current)
Karson N.
Line 3: Line 3:
 This article describes how to replace WordPress's internal cron mechanism with a cron job run by the operating system's ''%%cron%%'' daemon. This article describes how to replace WordPress's internal cron mechanism with a cron job run by the operating system's ''%%cron%%'' daemon.
  
 +\\
 ===== What is wp-cron and How Does it Affect Your WordPress Site ===== ===== What is wp-cron and How Does it Affect Your WordPress Site =====
  
Line 8: Line 9:
  
 This is how it looks in Apache logs: This is how it looks in Apache logs:
 +<code>
   "POST /wp-cron.php?doing_wp_cron=1517537460.9037239551544189453125   "POST /wp-cron.php?doing_wp_cron=1517537460.9037239551544189453125
 +</code>
  
 Therefore, the more visits the website gets, the more frequently ''%%wp-cron.php%%'' has to be checked. This may cause significant burden in terms of processing power on sites with high traffic. Therefore, the more visits the website gets, the more frequently ''%%wp-cron.php%%'' has to be checked. This may cause significant burden in terms of processing power on sites with high traffic.
Line 14: Line 17:
 There are two stages to the process: disabling WordPress's cron mechanism, and setting the task as a cronjob. There are two stages to the process: disabling WordPress's cron mechanism, and setting the task as a cronjob.
  
 +\\
 ===== Disabling via cPanel ===== ===== Disabling via cPanel =====
  
 Using cPanel, disabling the wp-cron can be done via the File Manager, and setting up the cronjob can be done in the "Cron Jobs" section of cPanel. Using cPanel, disabling the wp-cron can be done via the File Manager, and setting up the cronjob can be done in the "Cron Jobs" section of cPanel.
  
 +\\
 ==== Disabling wp-cron via File Manager ==== ==== Disabling wp-cron via File Manager ====
  
 Go to cPanel and click on "File Manager". Find the file ''%%wp-config.php%%'' which also resides in the site's root directory, and click on "Edit" in the top menu: Go to cPanel and click on "File Manager". Find the file ''%%wp-config.php%%'' which also resides in the site's root directory, and click on "Edit" in the top menu:
  
-{{:cms:wordpress:wp_cron_wpsettings_open.jpg?nolink&600|}}+{{:cms:wordpress:wp_cron_wpsettings_open.jpg?nolink&1200|}}
  
 Add the following line in the file: Add the following line in the file:
 +<code>
   define('DISABLE_WP_CRON', true);   define('DISABLE_WP_CRON', true);
 +</code>
 +
 You may add this in any place between existing ''%%define%%'' directives, for example at the very top just after ''%%<?php%%'' symbols: You may add this in any place between existing ''%%define%%'' directives, for example at the very top just after ''%%<?php%%'' symbols:
  
Line 34: Line 42:
 Now WordPress will not run the ''%%wp-cron.php%%'' script every time someone visits your site. However, there is still a need for the cron jobs to run periodically. Now WordPress will not run the ''%%wp-cron.php%%'' script every time someone visits your site. However, there is still a need for the cron jobs to run periodically.
  
 +\\
 ==== Setting Up Cron Jobs in cPanel ==== ==== Setting Up Cron Jobs in cPanel ====
  
Line 49: Line 58:
  
 And finally, you need to set up the command to run. Please note that you need to run the script with the specific PHP settings used by your site, e.g., the correct PHP version. That means that you need to invoke the ''%%php%%'' command from inside the root directory. For example, if the site's root directory is ''%%/home/wp/public_html%%'', the command would be: And finally, you need to set up the command to run. Please note that you need to run the script with the specific PHP settings used by your site, e.g., the correct PHP version. That means that you need to invoke the ''%%php%%'' command from inside the root directory. For example, if the site's root directory is ''%%/home/wp/public_html%%'', the command would be:
 +<code>
   cd /home/wp/public_html; php -q wp-cron.php   cd /home/wp/public_html; php -q wp-cron.php
 +</code>
  
 {{:cms:wordpress:cp_cron_command.jpg?nolink&600|}} {{:cms:wordpress:cp_cron_command.jpg?nolink&600|}}
Line 57: Line 68:
 {{:cms:wordpress:cp_cron_list.jpg?nolink&800|}} {{:cms:wordpress:cp_cron_list.jpg?nolink&800|}}
  
 +\\
 ===== Disabling wp-cron and Setting Up System Cron Job via SSH ===== ===== Disabling wp-cron and Setting Up System Cron Job via SSH =====
  
 Go to the site's root directory, for example ''%%/home/wp/public_html/%%'': Go to the site's root directory, for example ''%%/home/wp/public_html/%%'':
 +<code>
   cd /home/wp/public_html/   cd /home/wp/public_html/
 +</code>
  
 Open file ''%%wp-config.php%%'' in a text editor, for example ''%%vi%%'': Open file ''%%wp-config.php%%'' in a text editor, for example ''%%vi%%'':
 +<code>
   vi wp-config.php   vi wp-config.php
 +</code>
  
 Add the following line just after the ''%%<?php%%'' line on the top: Add the following line just after the ''%%<?php%%'' line on the top:
 +<code>
   define('DISABLE_WP_CRON', true);   define('DISABLE_WP_CRON', true);
 +</code>
  
 Save and exit the text editor. Save and exit the text editor.
  
 Open the crontab editor. If you are logged in as the cpanel user then run: Open the crontab editor. If you are logged in as the cpanel user then run:
 +<code>
   crontab -e   crontab -e
 +</code>
  
 If you are logged in as root and you need to edit the crontab for a cpanel user then run: If you are logged in as root and you need to edit the crontab for a cpanel user then run:
 +<code>
   crontab -e -u USERNAME   crontab -e -u USERNAME
 +</code>
  
 Add the following line, save, and exit the text editor: Add the following line, save, and exit the text editor:
 +<code>
   5 */6 * * * cd /home/USERNAME/public_html; php -q wp-cron.php   5 */6 * * * cd /home/USERNAME/public_html; php -q wp-cron.php
 +</code>
  
 To check the crontab run: To check the crontab run:
 +<code>
   crontab -e -l USERNAME   crontab -e -l USERNAME
 +</code>
  
-You can find more information on crontab syntax [[https://en.wikipedia.org/wiki/Cron|here]]. +You can find more information on crontab syntax ((https://en.wikipedia.org/wiki/Cron))[[https://en.wikipedia.org/wiki/Cron|here]].
cms/wordpress/cron-convert.1570732293.txt.gz · Last modified: 2019/10/10 13:31 by Karson N.