run a cron task without obstructing page load?

Cron tasks don’t directly affect page load besides the 0.01s timeout (of course, they do affect server load, so they can impact page load indirectly). My hunch is that your PHP config is the issue. The cron tasks run like any other web request, and they’re subject to PHP’s max_execution_time INI setting. If this is … Read more

How to make sure a wp-cron job runs

Yes. No, because the scheduled job hasn’t reached the time yet. Yes, but not until 7:03pm. Basically, any hit to the site after the scheduled time will cause the queued job to run. The WP_Cron is a “best effort” system, not an exact timer. This is generally good enough though, since if nobody’s visiting the … Read more

wp_next_scheduled returning a past timestamp

Well, as I was working on an existing site which as maaaaany plugins already installed, I figured out that there was a define(DISABLE_WP_CRON,true); So when you seems to have the same problem than me. Do a research of define(DISABLE_WP_CRON,true); in your files.

How to run multiple Async HTTP requests in WordPress?

The (built-in) Requests class lets you call multiple requests simultaneously: Requests::request_multiple. <?php $requests = Requests::request_multiple([ [ ‘url’ => ‘https://www.mocky.io/v2/5acb821f2f00005300411631’, ‘type’ => ‘GET’, ‘headers’ => [ ‘Accept’ => ‘application/json’ ], ], [ ‘url’ => ‘https://www.mocky.io/v2/5acb821f2f00005300411631’, ‘type’ => ‘POST’, ‘headers’ => [ ‘Accept’ => ‘application/json’ ], ‘data’ => json_encode([ ‘text’ => ‘My POST Data’ ]) ], [ … Read more

wp_schedule_event() on specific time, daily

time() only returns current time, it doesn’t accept any inputs. $time = time(); // works out to 2016-04-11T12:11:34+00:00 What you want is midnight tomorrow: $tomorrow = strtotime( ‘tomorrow’ ); // works out to 2016-04-12T00:00:00+00:00 Note that these are PHP functions and they ignore WP timezone, since it resets PHP time zone to UTC. So if … Read more

Get frequency of scheduled event

This is an old question, but hopefully this helps someone facing the same issue. We can use wp_get_schedule( $hook ) to retrieve the cron schedule for the hook. Then we can use wp_get_schedules() to retrieve the supported cron recurrences. Find the correct array value and return it. /** * Retrieve Cron interval for hook. * … Read more

wp-cron.php is triggered, but scheduled post is not published

The _get_cron_array() function gets the ‘cron’ option out of the database. The cron option contains an array consisting of a series of unix-timestamps and action hooks. So, when the timestamp is reached, then the action hook is called. The timestamp of 1465529020 is the equivalent of June 10th, 2016, at 3:23am in UTC time. The … Read more