0

Wordpress cron job

My site health said cron evens has missed schedule, so I installed “Wp control” plugin to check the cron evens.

Normally “next run” will show the future time, but in my case it shows a time in the past like 6hours ago.

I’ve tried to disable all plugins, reinstall the Wordpress, clean the database, restart the server, the problem is still there.

After restart the server, I find out this happened right after a cron job ran, so each cron job will never run a second time because the next run will always be in the past!

Weird thing is there are 4 other Wordpress instances in the very same server and all 5 sites share the same php7.4 and MySQL, but their corn job is acting normally.

I’ve checked the date time settings, I’ve also tried to raise the number of php “max_children” and “start_servers” because some google results said it could be a php memory related issue, but still not able to solve this.

Please help me, how to debug a cron job issue like this and how to solve it?

Thank you for your attention!

2
  • Did you click that "More Information" link in the notice at the top? It seems directed at your issue. What did it tell you? Have you checked Tools > Site Health to see if any cron issues are reported? Commented Sep 15, 2021 at 16:45
  • @JacobPeattie Yes the reason I install "WP control" plugin to check cron jobs is I saw the warning informations in Site Health as I mentioned above. And "More Information" links to here: github.com/johnbillion/wp-crontrol/wiki/… but it is not really the solution I guess.
    – Duke Yin
    Commented Sep 16, 2021 at 1:51

1 Answer 1

0

Cron jobs in the past are cron jobs that have not had the opportunity to run yet.

Very Few Visitors

Unless you system has a system level cron that is configured to trigger WP Cron at predictable intervals you won't be able to use WP Cron for precise timekeeping.

This is because WP Cron will be triggered when users visit in a non-blocking self request to wp-cron.php, so if nobody visits your site, no cron jobs can run.

WP Cron is Turned Off

Perhaps WP_CRON is set to false in wp-config.php? This is common on sites that rely instead on manually triggering cron via system cron.

Either re-enable it, or fix the system cron that was meant to manually trigger WP Cron

PHP Errors

It could be that the next cron job due also causes a fatal error, preventing it from completing and holding up the queue. Check your error logs.

Very Large Backlog/Jobs

Normally WP Cron can only run for a short period before it runs into the same time limit that stops webpages from loading forever. Likewise it would have the same memory limits.

So if your site has a lot of jobs, it may not be able to process all of them in time. Likewise, a custom job may take too long and not have enough time to complete. Usually this will show up in a PHP error log as time limit or memory limit errors

Main Site Errors

Because WP Cron is triggered by a non-blocking request at the very end of a page load, if your page crashes/breaks at the very end it may not have the chance to make the request. If this happens after the footer you might not notice this happens

4
  • Thank you Tom, It is odd that when nobody visit my site, the cron will be "not run" but the thing is the first run is ok after restat server, but the next run time will be in the past. And I tripple checked the wp-config.php, there is no cron related settings' been put there. I also suspect that the problem lies in php, but the strange thing is that other wordpress cron jobs on the same server are normal, they share the same php.
    – Duke Yin
    Commented Sep 16, 2021 at 1:53
  • it's more that WordPress has no way to set up regular recurring background tasks, so making a non-blocking request to itself at the end of sending a page is the workaround. Usually this shows up when people schedule a post for 1pm and it doesn't publish at exactly 1pm. You can manually trigger WP Cron from a system cron which makes it more predictable, e.g. my site runs it every 5 minutes via WP CLI, or by a curl request to directly hit the wp-cron.php URL, and managed hosts do this too. If you have that option I would highly recommend it
    – Tom J Nowell
    Commented Sep 16, 2021 at 9:34
  • Also, just because they share the same PHP doesn't mean that PHP will behave the same, data unique to that site could be triggering a bug. Do you have WP CLI access? If so you can directly run individual cron jobs or trigger the due jobs and see if it fails or not
    – Tom J Nowell
    Commented Sep 16, 2021 at 9:35
  • wp cron event run --due-now
    – Tom J Nowell
    Commented Sep 16, 2021 at 9:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.