I'm registering an event like:
wp_schedule_single_event( time(), 'do_custom_hook', array( $body ) );
Above that, I have added the following action:
add_action('do_custom_hook', 'process_custom_hook', 10);
function process_custom_hook($body){
// custom code here
}
However, sometimes the process_custom_hook function fires, while other times, it simply doesn't (it fires most times, though. It's missed about 10%-20% of the time)
The event is always returning true, meaning that it must have registered.
Also, while testing, I made sure that the arguments (body) is always different.
Any reason why this may occur?
process_custom_hook
instead of scheduling the event? Also, did you really make sure$body
was different each time and not accidentally the same in 10-20% of the cases? – Arandprocess_custom_hook
contains blocking code, this will anyway run while a user is trying to load the page - thus, will still affect users' page load times. For such blocking requests there are two options: using AJAX so the user isn't directly affected by the processing time, or use a real cron job invoking a PHP file requiringwp-load.php
and then performing theprocess_custom_hook
stuff. – Arandtime()
function is not always synced with Wordpress. You should usecurrent_time('timestamp')
or variations thereof when included in WP functions – Doncasterwp_schedule_single_event
function returns true, meaning, that it must have been scheduled, but doesn't run nor appear in the cron. Something must be telling it to skip the event... Is there maybe a maximum amount of times an event can be emitted in a given period of time? Or, should events be cleaned up (even though I schedule it only once, and they appear to be removed automatically after execution)? – Occludestrtotime('+10 minutes')
insteadtime()
pass whatever time you want. – Archaeo$body
is always different? – Alicealicea