CronJob

A cronjob is a function that will run periodically on your site. For example, in Madara, we use cronjob to do the following work:

  • delete temporary folders which are used when uploading chapters
  • send notifications to manga’s subscribers
  • If you use a crawler, then the crawler also has its own cronjobs to crawl data

WordPress provides its own cronjob system. Howevever, the way it works is to depend on user visit. When there is a page load (ie. user visit), WordPress checks if it needs to run a job and then trigger. This will consume some of the resource on your site.

To improve it, you can setup a real cronjob on your server. Most hosting providers provide this feature. You can search for Cronjobs on your server management tool (cPanel, Plesk, WHM,…) to access it. In the command text field, enter something like this

*/5 * * * * wget -q -O – ‘[your_site_url]/wp-cron.php?doing_wp_cron >/dev/null 2>&1

In which you need to replace [your_site_url] with your own site URL (full URL with http or https). The first few * characters are the directive which tell the cronjob to run in an internal. It has this format

* * * * *
| | | | |
| | | | —– Day of week (0 – 7) (Sunday=0 or 7)
| | | ——- Month (1 – 12)
| | ——— Day of month (1 – 31)
| ———– Hour (0 – 23)
————- Minute (0 – 59)

The first */5 means it will run every 5 minutes. Similar logic apply to other asterisk. For example this one

* */2 * * *

will tell the cronjob to run every 2 hours.

If you have multiple cronjobs on your site, then you should setup the above internal string to match the smallest internal among all your cronjobs.

Additionally, you will need to disable default WordPress cronjobs feature in your [root-directory]/wp-config.php file – add this line

define(‘DISABLE_WP_CRON’, true);

SHARE THIS POST

Leave a Reply

Your email address will not be published. Required fields are marked *

*

four + 9 =