[wp-hackers] WP cron and "multi-threading"
ryan at boren.nu
Sun Oct 8 20:11:37 GMT 2006
Owen Winkler wrote:
> I've used wp_schedule_event() to register a cron event during the
> activation of my plugin, and I have a couple of issues.
> #1: The cron event seems to leave remnants of non-existent args in the
> serialized options array. Every time it runs it adds an array wrapper
> to the existing zero-length array of arguments. I don't know if this
> patch (http://trac.wordpress.org/ticket/3169) will fix it. I'm not sure
> if it's causing any issues with the plugin itself since I'm not using
> the parameters, but I don't think it will be a problem, at least until
> the size of the data exceeds the field length.
I committed 3169.
> #2: I need the cron to run *exactly once* at each interval. Assuming
> that traffic on the site is buzzing along, the current cron
> implementation could allow events to be processed more than once,
> depending on how long it takes for the hooked function to run. In my
> case, the computation in the cron hook usually takes 2 seconds or more,
> leaving plenty of room for another incoming hit to trigger the same event.
> I've implemented a flock() check in my own code, something I'd rather
> not do. It might be beneficial to rearrange the cron code so that it
> unschedules the event before it executes it.
> Any other clever suggestions as to how to keep the cron from executing
> more than once on a single registered instance would be helpful.
I have nothing clever to offer. Even unscheduling beforehand leaves a
window of contention, although the window is narrowed.
More information about the wp-hackers