• I am trying to setup scheduling single event cron wp_schedule_single_event function, where i checked by passing first parameter as strtotime('+1 days'); and it setup cron perfectly for 24 hours, if i do things like below it setup 12 hours no matter what?

    $last_date_of_membership = "20-02-2017"; // d-m-y europe style 
    $penalty_day = strtotime($last_date_of_membership."+1 days");
    wp_schedule_single_event($penalty_day,'some_hook_name');

    It just schedule 12 hours not 24 hours, later that i tried with h:i:s still the same 12 hours is what scheduled in cron.

    I checked the documentation of wordpress where it state use unix timestamp which is gmt https://codex.www.ads-software.com/Function_Reference/wp_schedule_single_event

    Are there any limitation where we cannot use strtotime which is converted from date in scheduling cron? If so please suggest someother alternate to overcome this problem.

    NOTE: I just specified tomorrow date as an example.

    Any suggestion would really great?

    Thanks.

Viewing 1 replies (of 1 total)
  • Moderator bcworkz

    (@bcworkz)

    There’s a number of factors that could skew wp-cron timing to explain your observations. For example, specifying strtotime(’20-02-2017′) yields a time stamp on that date at 00:00 hours UTC (1487548800). Depending on your time zone, the server’s time zone, and when you scheduled the time the day before, that may only be an hour or two ahead, or possibly the time has already passed!

    The time scheduled events actually run can be additionally erratic because events will not fire until their scheduled time has passed (if only by seconds) AND someone (or thing) visits the site. On seldom visited sites, the time an event runs can be much later than the scheduled time. All the event manager does before calling an event is to verify the scheduled event time is earlier than the current time, according to the server’s clock. If an event is scheduled 1 second after the current time, it will not be called until someone visits the site again later to trigger another wp-cron.php call. This will not happen for at least 10 minutes and possibly many hours later, depending on visitation.

    What time stamp is stored is also variable, depending on what functions and format you used. Some take into consideration locale time zone, others not. Some schedule accurate to the second, some round down to the closest date at 00:00 hours UTC.

    For the most accuracy, ensure you include a UTC time factor in your time stamp, not just a date. Verify the server’s clock is accurate for it’s location. Ensure your site is frequently visited. Services like Uptime Robot can do this. On ‘nix severs, a true crontab entry that makes WP requests can be used.

    Despite similar function and terminology, there is no relationship between ‘nix crontab and wp-cron. The former is accurate and reliable, but ‘nix only; the latter is not accurate, but works on Windows servers. wp-cron is much easier to implement from plugin or theme code and for most applications, accurate enough. Critical timing applications should use crontab, assuming it’s available.

Viewing 1 replies (of 1 total)
  • The topic ‘wp_schedule_single_event schedule with specific date?’ is closed to new replies.