Support » Plugins » Hacks » How can I massively delete cron tasks from outside WP?

  • Hello guys, I’m stuck with a weird problem. I found the reason for this site to be sloooow and generating hundreds of entries in the PHP error log: it has THOUSANDS of residual cron tasks. I need to delete them and I’ve tried with this script

    add_action('init', 'clear_crons_left');
    function clear_crons_left() {
       wp_clear_scheduled_hook('1439943287');
    }

    But since the list of hooks is in the thousands, it takes forever even if I paste a lot of lines.

    You can check a screen capture here:
    https://drive.google.com/file/d/0B4ZIdz9VEIQGZURPTl9KdW9DN0U/view
    And the list goes up to 9k lines like that…

    How can I delete all that crap? What if I blank the cron key in the database? I thought about replacing it with other from a healthy WP site… may I break something?

    Any ideas?

Viewing 4 replies - 1 through 4 (of 4 total)
  • Well, I tried replacing the value for cron entry in the database. And it worked but… the crappy cron tasks continue regenerating and being added to the list. I deactivated all plugins and switched to Twenty Fifteen theme but it’s not stopping. Any idea?

    Here’s the nuclear option you can use as a last resort. Edit your wp-config.php file, and just before it says “that’s all, stop editing”, add the following line:

    define('DISABLE_WP_CRON', 'true');

    This should be done as a last resort because it breaks everything that depends on CRON tasks, such as posting with a future date. It may help you solve your problem, though, so use it wisely. 🙂

    But does it FULLY DELETE all of the cron entries in the database? Cause that is what I really need.

    No, it won’t delete the cron entries, it will only stop them from firing.
    I think you need to find what and why you are getting so many cron entries created, probably a plugin, first fix why it is flooding your server with entries. Then get into your database with phpmyadmin, grab a backup, and then create a query that finds all the zombie cron entries and work out how to kill them. One way would be to set them all into the past, then re-enable them and have them all fire at once, stand back and wait while this happens, don’t do this if they are themselves re-scheduling more cron entries.
    Maybe you need to follow up on the PHP errors first instead (but after disablimg cron).
    Somewhere you have a real bottom line root cause, once you fix it things will get earier.
    Once you have it sorted out you want to re-enable cron.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘How can I massively delete cron tasks from outside WP?’ is closed to new replies.