[wp-hackers] Pseudo-Cron
Otto
otto at ottodestruct.com
Fri Sep 21 15:48:05 GMT 2007
Really? I didn't think that the new cron stuff was complicated enough
to even need documentation. It was just obvious, sort of thing.
Here's the gist of it:
Parameters: All functions.
$timestamp - Refers to the time the job will run. The job will run at
the next time the page is accessed after this timestamp. Create it
using standard php time functions, like time() or str_to_time() or
whatever. In other words, this should be a unix timestamp value.
$hook - The action hook to activate. wp-cron doesn't run functions, it
activates action hooks. You create your functions and then create your
own hooks with add_action('my_hook','my_function').
$args - an array of arguments to pass to the actions. Optional, of course.
$recurrance - For repeating events, how often the event should be run.
This can be 'hourly' or 'daily', or you can add your own repeating
values by modifying the array given to you with the cron_schedules
filter.
The functions:
function wp_schedule_single_event( $timestamp, $hook, $args = array())
- Schedules a one time event. At $timestamp, $hook will be called with
do_action.
function wp_schedule_event( $timestamp, $recurrence, $hook, $args =
array()) - Schedules a recurring event.
function wp_reschedule_event( $timestamp, $recurrence, $hook, $args =
array()) - Reschedules a given event. There's not a lot of reasons to
use this.
function wp_unschedule_event( $timestamp, $hook, $args = array() ) -
Unschedules a specific event. Also not a lot of reason to use this.
function wp_clear_scheduled_hook( $hook ) - Unschedules an event even
if you don't know when it's scheduled. This simply kills all events
that will trigger the given $hook. This is very useful.
function wp_next_scheduled( $hook, $args = array() ) - returns the
$timestamp of when a given event will run, given the known hook and
args for it.
function spawn_cron() - Never call this, used internally.
function wp_cron() - Never call this, used internally.
function wp_get_schedules() - Used internally to get the list of
recurring schedules. If you add a filter to 'cron_schedules', you can
modify this to have your own repeating schedule values.
function wp_get_schedule($hook, $args = array()) - Not really any good
reason to use this, but it can get you the recurrence value for a
given hook/args set.
Pretty straightforward, I thought. What part in particular is giving you issues?
On 9/21/07, Jeremy Visser <jeremy.visser at gmail.com> wrote:
> Matt wrote:
> > On 9/20/07, Matt <speedboxer at gmail.com> wrote:
> >> Is $timestamp in relation to GMT?
> >
> > Nevermind, I understand it now.
>
> You do? Heck, I've been trying to understand it for 3 months now and
> still haven't succeeded in even scheduling _anything_. That makes me
> feel really awful. :(
> _______________________________________________
> wp-hackers mailing list
> wp-hackers at lists.automattic.com
> http://lists.automattic.com/mailman/listinfo/wp-hackers
>
More information about the wp-hackers
mailing list