WordPress crons are different from traditional Linux or Windows crons. Traditional cron runs as independent processes at regular interval. WordPress crons are php hooks which piggy back on a visitor requests. Few points to note in wordpress crons:
- When a cron is scheduled, it is run the moment a user visits the site after the scheduled time. So the running time can be much later than scheduled time.
- The cron may slow down the user request. Here is the action hook in default-filters.php which is used to invoke cron code:
add_action( 'init', 'wp_cron' );
Checking and running crons in each user request can potentially impact performance.
- At each user request wordpress checks for the existence of any scheduled cron and calls spawn_cron. Here is code snippet from spawn_cron function in cron.php
$cron_request = apply_filters( 'cron_request', array( 'url' => site_url( 'wp-cron.php?doing_wp_cron=' . $doing_wp_cron ), 'key' => $doing_wp_cron, 'args' => array( 'timeout' => 0.01, 'blocking' => false, 'sslverify' => apply_filters( 'https_local_ssl_verify', true ) ) ) );wp_remote_post( $cron_request['url'], $cron_request['args'] );
It seems that it has a low timeout and its a non blocking wp_remote_post. So it should not impact the user thread too much. But if there are to many crons activities, it may still have some impact on user request response time.
In you own your own Linux hosting server (or any other) then a better approach is to disable the wordpress cron and setup a Linux cron. Here are the steps:
- Add this entry to wp-config.php
This will ensure that no cron related work in done in any user request. This will reduce some mysql database queries also.
- Setup a Linux cron after every 5 min or so.
*/5 * * * * wget -q -O - http://infoheap.com/wp-cron.php
You can run it less frequently in case you don’t have any cron task which need that kind of frequency.
I prefer to keep the user request thread as light and simple as possible. This lead to overall a better user experience.