0

Are there some timer hooks to trigger event like this?

add_action("one_min_timer", "my_handler");
function my_handler() {
   //checking something every 1 min
}
  • yes, read this : codex.wordpress.org/Function_Reference/wp_schedule_event – mmm Jul 13 '16 at 12:24
  • 1
    However wp_schedule_event works only when somebody is on website. If there is no one for hour "timer hook" doesn't work. – user94212 Jul 13 '16 at 12:26
  • @Tomve Why WP doesn't provide a real timer regardless if someone visit site? I hope to execute a background job. There is any workaround? – KyL Jul 13 '16 at 12:31
  • @KyL, you need to OS related cron jobs for such cases. – bravokeyl Jul 13 '16 at 12:32
  • @Tomve About wp_schedule_event I have a question. When visiting wordpress, web server forks a child process to deal with new request. Which processes' wp_schedule_event will be triggered, parent process or child process? – KyL Jul 13 '16 at 13:24
0

You can use the native PHP sleep() function in WordPress for timers in seconds, or usleep() for timers in microseconds:

http://php.net/manual/en/function.sleep.php

http://php.net/manual/en/function.usleep.php

  • I think without thread, sleep will hang up whole website. And pthread of PHP needs extension module. – KyL Jul 13 '16 at 15:15
  • @KyL You could also use a cron job :) – Tammy Shipps Jul 13 '16 at 18:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.