0

I want to schedule an action to be run daily. This action can take up to a few seconds.

Question is: is WP-Cron the suitable mechanism (compared to, say, classic Unix cron) for such action?

The reason why I'm asking is that, as far as I understand, all WordPress hooks are triggered by HTTP requests, probably coming from regular visitors or administrators. If the action is run in the same thread as the triggering HTTP request, I'm afraid the later will be affected by the scheduled action. Bottom line: once per day, an unlucky visitor might notice a huge delay while accessing the site.

So can I register my action with wp_schedule_event? If so, could you describe how WordPress works around this issue? If not, what are the options? I really don't want to deal with cron directly, plus my plugin should also work on Windows systems.

2
  • WP CLI is another candidate for long running tasks, what is your time consuming task?
    – Tom J Nowell
    Commented Jun 15, 2015 at 14:33
  • Another option would be to setup your function as if it were a AJAX request and "ping" it with a real cron job: wordpress.stackexchange.com/a/190502/21376
    – s_ha_dum
    Commented Jun 15, 2015 at 18:40

1 Answer 1

0

Apparently, WP-Cron jobs are run in a separate process. This can raise some issues, but at least the answer to the question above is: yes, a time-consuming action can be scheduled with WP-Cron. The triggering HTTP request won't be delayed because of it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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