[wp-hackers] wp_cron - odd behavior

Jeremy Clarke jer at simianuprising.com
Fri Feb 18 18:58:33 UTC 2011

This isn't a direct answer to your question but my advice is to set up
something that logs to a file when your wp-cron-attached function runs. I've
found that's the only really safe way to know WTF wp-cron is actually doing.

It's possible your local server isn't happy about email or something, but if
the first thing your script does is add a line to a debug file then you can
track what hook fired, when it fired and you can debug whether there is an
unrelated email or other error causing the failure.

In terms of the single events, are you sure you're using unique
slugs/labels? I'm pretty sure you can overwrite a cron event by rescheduling
the same name to a new time.

Also this is something you probably already know but the wp-cron system only
fires when someone visits the site. So without organic traffic (local
install where it's just you) it will only fire when you load the site
yourself. If you schedule three events one per hour and come back in three
hours they will all fire simultaneously, resulting in a different effect
than what you expected. The result is that it will not behave like in the
wild and you need to lower the timeframes involved when testing to avoid
driving yourself nuts. Here's some simple code to add an 'Every Minute'
timeframe to use when testing:

 * Add filter on cron_schedules hook to insert custom scheduling times
 * @see wp_get_schedules() which calls the filter and defines default
 * @param array $empty_array Empty array passed in by wp_get_schedules()
 * @return array Filtered array including our custom scheduling periods
function gv_filter_cron_schedules($empty_array) {
    $new_schedules = array(
        'every_minute' => array(
            'interval' => 60,
            'display' => __('Every Minute'),

    return array_merge($empty_array, $new_schedules);;
add_filter('cron_schedules', 'gv_filter_cron_schedules');

Jeremy Clarke • jeremyclarke.org
Code and Design • globalvoicesonline.org

More information about the wp-hackers mailing list