[TUT] Optimizing WordPress with a real CRON job

Discussion in 'Blogging' started by Zak_A, Oct 10, 2012.

  1. Zak_A

    Zak_A Jr. VIP Jr. VIP Premium Member

    Mar 16, 2008
    Likes Received:
    WP designer & developer
    Western Europe
    WordPress comes with a built in automation function called wp_cron. It is used for various WP maintenance (updates check etc.), to publish scheduled posts that are created with a date in the future, and by many plugins with automated features, such as autoblogging plugins.

    Though wp_cron is not perfect. You might have seen missed schedules already if you use them. This is because wp_cron is not actually a cron job, but rather a "pseudo cron job" that fires when a page is loaded (i.e., when you get a visitor to your site.)
    When someone visits you site, wp_cron is fired during page load, and checks the database to see if there is any pending action to take. Thus if you don't get visits during a given period, any scheduled actions will not be triggered.
    Another issue is that when someone comes to your site and there are pending action, running them during page load can increase the page load time (which is not good for user experience).

    Here's a simple tweak to replace wp_cron with a real CRON job to solve these issues.

    PART 1: Disabling wp_cron.

    #1 - Using your FTP program or file manager in cPanel, download the file called wp-config.php (located at the root of your WP installation)
    #2 - Open wp-config.php with a text editor and paste the following line anywhere
    (if not sure, you can paste this below define('DB_COLLATE', ''); ) :
    define('DISABLE_WP_CRON', true);
    #3 - Upload wp-config.php back to your server.

    PART 2: Setting a real CRON job to replace wp_cron

    #4 - In your cPanel, go to "cron jobs".

    #5 - Under the "add new cron job" section, choose a 15 minutes interval (this setting offers the best performance)

    #6 - In the "command" field, paste the following line (just change YOURWEBSITE.COM with the actual URL of your WP site!)
    wget -q -O - http://YOURWEBSITE.COM/wp-cron.php >/dev/null 2>&1
    #7 - Click "Add New Cron Job" and you're done!

    That's it, you've just replaced wp_cron with a real CRON job!
    No more missed schedules, and you have optimized your site speed on every page load!
    • Thanks Thanks x 2