[wp-hackers] wp_cron - odd behavior
Otto
otto at ottodestruct.com
Sat Feb 19 17:43:34 UTC 2011
On Fri, Feb 18, 2011 at 10:06 PM, Jeff Rose <jeff at jeffrose.ca> wrote:
> Thanks for the replies, but either I wasn't clear about my problem, or your
> answers are off the mark.
>
> Most of the time, the function inserts into the wp_cron, but sometimes it
> just doesn't, even though a debug running shows the correct values being
> passed 100% of the time. Sometimes the job is missing entirely and others it
> sets to Jan 1, 1970 (or whatever the beginning of the epoch is).
>
> I've ensured that all cron's would be scheduled for the future (2-3 days
> out) and more than 10 minutes apart, so the obvious stuff seems correct.
Without actually seeing your code, there's probably no way anybody can
answer your question.
The most likely cause is that you have a bug in your code somehow. If
you're getting cron jobs scheduled for 1970, then you're probably
passing a zero in as the first parameter to wp_schedule_single_event.
The scheduling functions aren't particularly complex. All they're
doing is to modify the cron array.
Now, your events not being scheduled may be understandable if they are
totally identical (matching hook+args). wp_schedule_single_event does
look for an identical event scheduled to happen within 10 minutes
after the time you're passing it, and prevents the new scheduling.
This is not obvious at first.
Say I schedule an event for 2 pm. I now am unable to schedule that
same event for any time after 1:50 pm, because the 2 pm event exists.
If I try, wp_schedule_single_event will simply return without
scheduling the event.
This has implications that most people might not realize.. Because if
I schedule an event for 1970 (zero), I'm now unable to schedule the
identical event for any time after 1970... If your events are wholly
identical, then you will have trouble scheduling more than one of them
unless your timing is tricky. In such cases, you should use a periodic
event using wp_schedule_event instead.
-Otto
More information about the wp-hackers
mailing list