[wp-trac] [WordPress Trac] #18100: Cron Loop does not work

WordPress Trac wp-trac at lists.automattic.com
Wed Jul 13 14:40:36 UTC 2011


#18100: Cron Loop does not work
--------------------------+------------------------------
 Reporter:  luis.ferro    |       Owner:
     Type:  defect (bug)  |      Status:  new
 Priority:  normal        |   Milestone:  Awaiting Review
Component:  Cron          |     Version:  3.2
 Severity:  blocker       |  Resolution:
 Keywords:                |
--------------------------+------------------------------
Changes (by kawauso):

 * keywords:  cron, reschedule =>


Old description:

> The cron loop existing on cron.php in the wp-includes does not work.
>
> The wp_cron() shows code that doesn't re-lists recurring events and does
> not fire any event. There is no other code firing those events.
>
> This code is calling for a "callback" array element that is not set on
> the scheduler array.
>
> After checking wp-cron.php, and adapting the code from that to wp_cron(),
> now everything works as it should.
>
> Changed function looks like:
>
> /**
>  * Run scheduled callbacks or spawn cron for all scheduled events.
> Adapted from wp-cron.php
>  *
>  * @since 2.1.0
>  *
>  * @return null When doesn't need to run Cron.
>  */
> function wp_cron()
> {
>
>     // Prevent infinite loops caused by lack of wp-cron.php
>     if (strpos($_SERVER['REQUEST_URI'], '/wp-cron.php') !== false ||
> (defined('DISABLE_WP_CRON') && DISABLE_WP_CRON))
>         return;
>
>     if (false === $crons = _get_cron_array())
>         return;
>
>     $local_time = time();
>     $keys = array_keys($crons);
>
>     if (isset($keys[0]) && $keys[0] > $local_time)
>         return;
>
>     foreach ($crons as $timestamp => $cronhooks) {
>         if ($timestamp > $local_time)
>             break;
>
>         foreach ( (array)$cronhooks as $hook => $keys) {
>
>             foreach ($keys as $k => $v) {
>
>                 $schedule = $v['schedule'];
>
>                 if ($schedule != false) {
>                     $new_args = array($timestamp, $schedule, $hook,
> $v['args']);
>                     call_user_func_array('wp_reschedule_event',
> $new_args);
>                 }
>
>                 wp_unschedule_event($timestamp, $hook, $v['args']);
>
>                 do_action_ref_array($hook, $v['args']);
>             }
>         }
>     }
> }
>
> Cheers,

New description:

 The cron loop existing on cron.php in the wp-includes does not work.

 The wp_cron() shows code that doesn't re-lists recurring events and does
 not fire any event. There is no other code firing those events.

 This code is calling for a "callback" array element that is not set on the
 scheduler array.

 After checking wp-cron.php, and adapting the code from that to wp_cron(),
 now everything works as it should.

 Changed function looks like:
 {{{
 /**
  * Run scheduled callbacks or spawn cron for all scheduled events. Adapted
 from wp-cron.php
  *
  * @since 2.1.0
  *
  * @return null When doesn't need to run Cron.
  */
 function wp_cron()
 {

     // Prevent infinite loops caused by lack of wp-cron.php
     if (strpos($_SERVER['REQUEST_URI'], '/wp-cron.php') !== false ||
 (defined('DISABLE_WP_CRON') && DISABLE_WP_CRON))
         return;

     if (false === $crons = _get_cron_array())
         return;

     $local_time = time();
     $keys = array_keys($crons);

     if (isset($keys[0]) && $keys[0] > $local_time)
         return;

     foreach ($crons as $timestamp => $cronhooks) {
         if ($timestamp > $local_time)
             break;

         foreach ( (array)$cronhooks as $hook => $keys) {

             foreach ($keys as $k => $v) {

                 $schedule = $v['schedule'];

                 if ($schedule != false) {
                     $new_args = array($timestamp, $schedule, $hook,
 $v['args']);
                     call_user_func_array('wp_reschedule_event',
 $new_args);
                 }

                 wp_unschedule_event($timestamp, $hook, $v['args']);

                 do_action_ref_array($hook, $v['args']);
             }
         }
     }
 }
 }}}

 Cheers,

--

-- 
Ticket URL: <http://core.trac.wordpress.org/ticket/18100#comment:1>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software


More information about the wp-trac mailing list