FeaturesWP CloudPricingEE CLIContactMy Account

Features

Team Access & User Permissions

Server Setup & Management

Site Creation & Management

Deployments & Developer Tools

Firewall Protection

Speed & Caching

Backups & Recovery

Logs & Monitoring

Create WP Cloud Sites

All Features

Read Documentation

Install

Installation Guide

FAQ

Roadmap

Explore EE CLI

Resources

Commands

Handbook

Blog

Community

Forum

EasyExperts

Tutorials

Subscribe

Github

CLEAR

Start For Free

separator Tutorials separator WordPress separator Better wp-cron using linux’s crontab

Topics

On this page

Disable wp-cron

Setup a real cronjob

Is it recommend for high-traffic site?

Better wp-cron using linux’s crontab

WordPress has something called wp-cron. If you haven’t read about it, its fine. But please be aware that you cannot live without it! That is why, I am not asking you to disable wp-cron.

Disable wp-cron

Still, we need to disable WordPress default wp-cron behaviour by adding following line to wp-config.php file:


			define('DISABLE_WP_CRON', true);
		

Setup a real cronjob

From your Linux terminal, first open crontab:


			crontab -e
		

Then add a line like below in it.


			*/10 * * * * curl http://example.com/wp-cron.php?doing_wp_cron > /dev/null 2>&1
		

			OR
		

			*/10 * * * * cd /var/www/example.com/htdocs; php /var/www/example.com/htdocs/wp-cron.php?doing_wp_cron > /dev/null 2>&1
		

Please make sure you use correct path to wp-cron.php.

Alternately, you can also use WP-Cli


			*/10 * * * * cd /var/www/example.com/htdocs; wp cron event run --due-now > /dev/null 2>&1
		

Above will run wp-cron every 10 minutes. You can change */10 to */5 to make it run every 5 minutes.

Difference between two-lines is, first one uses PHP-FPM (or PHP-CGI) and second one uses PHP-CLI. CLI scripts do not have time limits. Depending on your setup, it may be desirable or undesirable.

Is it recommend for high-traffic site?

I haven’t digged into wp-cron a lot but what I know is that it executes on every page-load. So if there is a long running process which gets triggers by wp-cron, it will delay page loading for that user.

Using crontab, wp-cron is run by independent PHP process. So it will not interfere with any visitors page-request.

Because of this, we highly recommend running wp-cron via linux crontab rather than WordPress’s default way, irrespective of size or traffic of your site.

Moving WordPress To New Server (Faster)

PREVIOUS

404 error- Page not Found!!!

NEXT


Comments

  1. panda Avatar

    panda

    January 1, 2014

    great! I’ve followed your suggestions. hope this will fix wp-cron.php timeout (70 sec) issue in my LEMP.

    Do I need to restart some services after configuration?

    BTW: the first code has two times of “> /dev/null 2>&1”

    1. Rahul Bansal Avatar

      Rahul Bansal

      January 2, 2014

      Cron does not require restart.

      Thanks for finding typo. Updated article. 🙂

  2. Janice Avatar

    Janice

    February 24, 2014

    In the second example, why do I have have to cd into htdocs first?

    Wouldn’t this work?

    */10 * * * * php /var/www/example.com/htdocs/wp-cron.php > /dev/null 2>&1

    1. Rahul Bansal Avatar

      Rahul Bansal

      February 26, 2014

      wp-cron.php line has require_once ('./wp-load.php'); which in-turn looks for wp-config.php

      If you do not cd into proper wordpress folder, wp-cron will fail.

      1. Janice Avatar

        Janice

        February 27, 2014

        I guess you’re saying that the require_once relative path will be incorrect if we don’t cd in there first. That’s weird, but I get it.

        However, why do we then need an absolute path? Wouldn’t this work?

        cd /var/www/example.com/htdocs; php wp-cron.php > /dev/null 2>&1

        1. Rahul Bansal Avatar

          Rahul Bansal

          February 28, 2014

          Thanks for your suggestion. I will try that.

          I think absolute path is not required once we cd into webroot.

Features

Useful Links

Product

Other Products

Subscribe for curated product updates, tips, and announcements.

"*" indicates required fields

Instagram

This field is for validation purposes and should be left unchanged.

Email*

SIGN ME UP

Δ


© rtCamp, since 2009. All rights reserved.

Powered by