Categories
Webservers

Use Linux cron Instead of WP-CRON

WordPress has internal function called WP-CRON, By default every time a page is loaded in admin or on the front-end of your site, WordPress calls WP-CRON. To avoid this, best way optimize the efficiency of your WordPress cron jobs is to disable WP-CRON and set up a Linux cron job. 

PREREQUISITES

  • You need to have a working knowledge of Linux commands before you can use cron jobs effectively.

STEPS

  • The first step is to prevent WordPress from running WP-CRON automatically, just toss this in your wp-config.php

  • Edit wp-config.php file of your site with your favourite editor. I am using vim editor here

  • Now put the following line just below DB_COLLATE

/** The Database Collate type. Don't change this if in doubt. */
define('DB_COLLATE', '');

/** Disable the default WordPress Cron */
define('DISABLE_WP_CRON', true);

  •  Save and close the file. Above directives will disable wordpress default WP-CRON

  •  Now we will need to add the actual Linux cron to run the wp-cron.php file manually.

[[email protected]]# crontab -e

*/15 * * * *  wget -O /dev/null -o /dev/null https://mylinuxtips.info/wp-cron.php

The above commands tells the server to run wp-cron.php via wget. /dev/null is used to send both stdout and stderr to /dev/null which discards any output and errors.

  • That cron will call wp-cron.php every 15 minutes. You can use a different time here.

 

By Sushant Chawla

Over the past 11 years I have acquired very good knowledge of:

- Cloud Setup on Amazon, Rackspace with autoscaling, load balancers, etc
- LAMP architecture
- LNMP Architecture
- Apache, Nginx, Lighttpd
- Databases: MySQL and PostgreSQL
- Bash Scripting
- Configuration Management with Puppet
- Monitoring: Nagios, Zabbix, ICINGA
- Mail servers: Sendmail, Postfix, Exim
- Web Accelerators & Caching Setups with Memcache, Varnish & Redis
- Setup and Management of high availability applications clusters
- LDAP, Samba, NFS, FTP, DNS, DHCP, Openfire, Squid Proxy
- Subversion(SVN), GIT
- Control Panels: Plesk, Webmin, cPanel

Apart from Linux, I am a great sports star & regular traveller. I like working out and exploring various places.

Cheers ;-)

Leave a Reply

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