Skip to content

Instantly share code, notes, and snippets.

@khromov
Last active July 26, 2016 12:08
Show Gist options
  • Select an option

  • Save khromov/740578d08abd86dd093e to your computer and use it in GitHub Desktop.

Select an option

Save khromov/740578d08abd86dd093e to your computer and use it in GitHub Desktop.
WordPress CRON

So how does WP CRON work? Whenever an admin user loads WordPress, WP checks whether any CRON jobs need to run (they are scheduled by timestamp), and if they do, WordPress makes a secondary request to itself using the spawn_cron() function. This secondary page load will load /wp-cron.php, which in turn loads another full copy of WP.

Now we're in the secondary CRON request, you can see this as being run asynchronously with the request that spawned it - spawn_cron() uses a cute little trick and sets a very low timeout value when calling the secondary CRON request, the result being both requests run in parallel, see here: https://github.com/WordPress/WordPress/blob/2f3e567f44e7bc335b6795713ae970b4f37117cd/wp-includes/cron.php#L297

@khromov
Copy link
Copy Markdown
Author

khromov commented Aug 5, 2015

Snippet taken from a recent PR:
afragen/git-updater#272 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment