[wp-hackers] Best methodology for running wp-cron on separate server.

Andrew Nacin wp at andrewnacin.com
Tue Apr 2 16:30:03 UTC 2013

On Tue, Apr 2, 2013 at 11:51 AM, Ryan Frankel <ryan.frankel at gmail.com>wrote:

> 2.  I could have a web server that I weight very low in the load balancer
> that runs the cron.  The question then becomes how to tell wp-cron to run
> on only that server.  My initial attempt was to wrap all of the add_actions
> in an if that looked for a specific IP and have pingdom hit that server
> every minute to make sure the crons did run.  I didn't have much success
> with that because there is no guarantee that WP will try the cron on that
> specific server and if it is on a different on it seems it will just skip
> it.  I have seen some thought about adding a transient if it runs on
> another server but I'm not sure that that will scale nicely and we would
> end up with code all over the place.

The easiest way to accomplish this is to set up a cron job on that server
that runs `php wp-cron.php` every minute. Then disable the cron in
wp-config.php using DISABLE_WP_CRON. Or, you can trigger an HTTP request
(such as through pingdom, as you said) directly to wp-cron.php on that
server. That too, will fire the cron. There are plenty of more advanced
ways, such as by setting up an actual jobs system to manage scheduled
events. Note that hitting wp-cron.php will need to happen for every site —
this is a particular consideration in multisite. Again, there are more
advanced ways.


More information about the wp-hackers mailing list