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?
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