I have around 20 wp_cron()
functions like the following code. Almost all crons run hourly; a few are daily.
if ( ! wp_next_scheduled( 'my_task_hook' ) ) {
wp_schedule_event( time(), 'hourly', 'my_task_hook' );
}
add_action( 'my_task_hook', 'my_task_function' );
function my_task_function() {
//Complex Code
}
To increase server performance, and so as not to keep getting server limit messages from hosting companies, I want to make sure that only one cron runs at a given time... Is it possible?
The current accepted answer is great, but I have following question, that's why I start a bounty for this question.
Please read the accepted answer at first.
Let assume Cron 1 runs, My code of cron2 won't running because still we are inside the 5 minute or first cron is running still, but because of wp_schedule_event( time(), 'hourly', 'my_task_hook' );
running for cron2 I think WordPress consider as cron2 runs..... So basically code of cron2 code never run..... Or I have misunderstand something?