wp cron defies the real world’s cron concept, which is running tasks during low traffic time windows
the babble says that cron depends on site’s traffic or busy state, may run late and is not aboslutely wrong, but leads to false interpretation …
wp cron is, as any other wp function, always in a passive state waiting for a page load … and then and only then it might run
so the real description for how wp cron works is:
as long as your site is sleeping, wp cron is dead …
so now you know why your tasks are not running in a timely manner, wp cron became a marketing headline like WE HAVE IT!, but it isn’t a cron scheduler, it is the rowboat where the rowers are at lunch and the drummer takes his stroke seat after they are back … and then we hope the boat starts moving
shocked? don’t be, it’s wp …
how to manage the problem?
firstable you need to forget about how cron usually works, to get better scheduling you need to schedule in peak hours … sounds funny? and it is, actually it is absurd, but that is a way to get the work done
a better way is not to schedule periodically like every two hours, schedule the first run for “tomorrow 05:00” to avoid the immediate task trigger and if at the desired hour your site has traffic, then the chance is high that it runs as desired on time
still you’re a suspect to suffer the “no traffic syndrome” and your task may not run, so how to manage it?
at the end of your scheduled function you add some code to remove the now dead schedule, and reschedule for “tomorrow 05:00”
so that’s the best you can do, within wp, and assure that your task runs as expected every day at almost the same hour
if you need to be really sure then add somehow some page requests with curl or wget at the desired hour from an external site and you’re set, that is of course rediculous but should work to become the authority for your task …
being the plaster mason for a badly build wall is not satisfying, we know that and we have it already in the kitchen, more precisely it is already in the oven, we are finishing a unix cron timer api to stop the wp cron madness and to have a reliable source for running tasks on the hour and without trickery in low traffic hours
until then, keep calm and wp cron rescheduling it is
the wp cron misconcept
hakka quote … it is a bug, it is full of bugs, but the real bug is that wp devs don't think beyond their nose tips …

Leave a Reply