Title: Cron problem
Last modified: August 22, 2016

---

# Cron problem

 *  [sajtdavid](https://wordpress.org/support/users/sajtdavid/)
 * (@sajtdavid)
 * [11 years, 7 months ago](https://wordpress.org/support/topic/cron-problem-2/)
 * Hi!
 * I’m trying to schedule events but it acts very weird.
 * Schedule command:
    `wp_schedule_single_event( strtotime($_REQUEST['newtime'])-
   3600 + 10, 'event_for_new_home_post_trigger' );`
 * I ran it multiple times, and sometimes it worked sometimes it is not.
    Downloaded
   this plugin: [https://wordpress.org/plugins/cron-view/](https://wordpress.org/plugins/cron-view/)
 * and saw only 2 entries, while there should be more than 5.
 * dumped the output of the function and I got false, however there was no new entry
   at the cron view plugin. Checked the core cron.php, and found this line:
 *     ```
       $next = wp_next_scheduled($hook, $args);
       	if ( $next && $next <= $timestamp + 10 * MINUTE_IN_SECONDS ) {return}
       ```
   
 * So if there is a same event close to the new, it returns null.
    The docs can 
   be confusing here, since it says:
 * > (boolean|null)
   >  False if the event was cancelled by a plugin, null otherwise.
 * I wanted to find out which event is next to my event, so I ran wp_get_schedule,
   and it returned nothing.
    I used the wp_next_scheduled command too, and it returned
   the next event:
 *     ```
       var_dump(wp_next_scheduled('event_for_new_home_post_trigger'));
       	var_dump(wp_get_schedule( 'event_for_new_home_post_trigger' ));
       ```
   
 * =>
 * > int(1415340010) bool(false)
 * So I got no schedule, but I got the next schedule.. how is this possible?
 * Thanks for any kind of help.

Viewing 5 replies - 1 through 5 (of 5 total)

 *  Thread Starter [sajtdavid](https://wordpress.org/support/users/sajtdavid/)
 * (@sajtdavid)
 * [11 years, 7 months ago](https://wordpress.org/support/topic/cron-problem-2/#post-5458109)
 * Also, MINUTE_IN_SECONDS = 60, and the code is: $timestamp + 10 * MINUTE_IN_SECONDS.
   Does this means that, I can’t schedule event in **10 hours** before an other 
   event?
 *  Moderator [bcworkz](https://wordpress.org/support/users/bcworkz/)
 * (@bcworkz)
 * [11 years, 7 months ago](https://wordpress.org/support/topic/cron-problem-2/#post-5458217)
 * `$timestamp + 10 * MINUTE_IN_SECONDS` means you cannot schedule events within
   10 **minutes** of another. That may explain your discrepancies, I couldn’t say
   with the information presented.
 * Also be aware that scheduled events are not triggered until there is a site visit
   by someone after the scheduled time. This is a big problem on localhost, not 
   so much on a busy site. But if you need precise timing use your server’s cron
   tab independent of WP scheduled events.
 *  Thread Starter [sajtdavid](https://wordpress.org/support/users/sajtdavid/)
 * (@sajtdavid)
 * [11 years, 7 months ago](https://wordpress.org/support/topic/cron-problem-2/#post-5458245)
 * I see now how is it 10 minutes, thanks for explaining that.
    I understand that
   its problem on small sites, but its not the case, we got a quite busy site. One
   thing I still dont understand, why does wp_get_schedule returns false?
 *  Moderator [bcworkz](https://wordpress.org/support/users/bcworkz/)
 * (@bcworkz)
 * [11 years, 7 months ago](https://wordpress.org/support/topic/cron-problem-2/#post-5458287)
 * Yes, it does not make any sense. The `wp_get_schedule()` and `wp_next_scheduled()`
   both share nearly all the same source code. The only difference is the value 
   returned. Thus if one finds the event, the other should as well, identical logic
   is used.
 * The only explanation would be something happened between one call and the other.
   Obviously if something new were scheduled in between, one would fail and the 
   later would not. Less obvious could be some sort of caching issue where one got
   an old cache value and the other a new one or one directly from the options table
   where events are stored.
 * I’m just guessing though. The real answer is I have no idea, sorry.
 *  Thread Starter [sajtdavid](https://wordpress.org/support/users/sajtdavid/)
 * (@sajtdavid)
 * [11 years, 7 months ago](https://wordpress.org/support/topic/cron-problem-2/#post-5458309)
 * Okay, still thank you very much.
 * I’m still in trouble with these cron jobs. I’m using the plugin that I linked
   before which shows my tasks good, after I bypassed the 10 minute minute check
   in the core (did not figure out why didn’t let it run my script since there was
   5 hour difference between the events, but added not my hook condition to the 
   return so it adds my events now).
 * The function that I called was running perfectly if I called from site, but on
   cron did nothing. After some time (and pain) I figured out get_home_path is not
   available if its a cron job.
 * Basicly I tried to delete a folder. Recursive delete function did not work. Added
   code to email me the result for rename, and called it from the site. I got true.
   Scheduled an event calling the same function, and I got false.
 * It almost drove me crazy, then I changed the whole wp-content directory’s permissions
   to 777, and after that I was able to rename directories.
 * WP Cron in wordpress is kinda evil.

Viewing 5 replies - 1 through 5 (of 5 total)

The topic ‘Cron problem’ is closed to new replies.

 * In: [Hacks](https://wordpress.org/support/forum/plugins-and-hacks/hacks/)
 * 5 replies
 * 2 participants
 * Last reply from: [sajtdavid](https://wordpress.org/support/users/sajtdavid/)
 * Last activity: [11 years, 7 months ago](https://wordpress.org/support/topic/cron-problem-2/#post-5458309)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
