Given a site running on server A and server B with a load balancer, shared database/etc, and a regular wp-cron task, how would I make sure that wp-cron only runs on server A, never on server B?
Tell me more
×
WordPress Answers is a question and answer site for
WordPress developers and administrators. It's 100% free, no registration required.
|
I would create a constant in the The tricky part, as you mentioned is to get the cron running for sure, and not aborting if it's accidentally the wrong server. Try the function like this:
Now, you have a transient set when the cron would run on the other server, but is not executed. The Function The last step is to hook a function to the
That should do the trick. |
|||||
|
|
I'm currently testing this in wp-config.php:
Where wp4 is the name of the second server in the setup |
|||
|
|
wp-config.phpis loaded? Afterwards it should be a piece of cake, making a conditional in the callback function of thewp-crontask. – fischi Feb 5 at 11:29