[wp-trac] [WordPress Trac] #35968: wp_reschedule_event timestamp overridden when set in the future

WordPress Trac noreply at wordpress.org
Fri Feb 26 20:32:19 UTC 2016


#35968: wp_reschedule_event timestamp overridden when set in the future
-------------------------------+-----------------------------
 Reporter:  svovaf             |      Owner:
     Type:  defect (bug)       |     Status:  new
 Priority:  normal             |  Milestone:  Awaiting Review
Component:  Cron API           |    Version:  4.4.2
 Severity:  normal             |   Keywords:
  Focuses:  docs, performance  |
-------------------------------+-----------------------------
 I'm doing some work with WP cron and I noticed two issues in the
 '''wp_reschedule_event()''' code (wp-includes/cron.php).

 The first problematic logic is the following:
 {{{#!php
 <?php
         if ( $timestamp >= $now ) {
                 $timestamp = $now + $interval;
         } else {
                 $timestamp = $now + ( $interval - ( ( $now - $timestamp )
 % $interval ) );
         }
 }}}

 Based on the function documentation, '''$timestamp''' is the ''Timestamp
 for when to run the event.''
 Let's say that I want to set the first run of the rescheduled event in one
 hour from now. This if statement overrides the $timestamp based on the
 interval, practically ignoring my initial $timestamp. If the logic is
 correct, then something in the documentation should be changed because
 it's not clear at all.

 Btw. I searched trac and found this:
 https://core.trac.wordpress.org/changeset/10969

 The second issue I see is the last line in that same function:
 {{{#!php
 <?php
         wp_schedule_event( $timestamp, $recurrence, $hook, $args );
 }}}

 Inspecting the code of '''wp_schedule_event''' the cron is scheduled based
 on the given timestamp. What it means is if the originally scheduled task
 execution time does not match to the new rescheduled '''$timestamp''', it
 will not override the cron but will add a new one.

 Maybe be there's some "dark magic" behind the scenes that makes it all
 work, but from reading the code + documentation, things doesn't make
 sense.

--
Ticket URL: <https://core.trac.wordpress.org/ticket/35968>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list