0

According to codex,

Schedules a hook which will be executed by the WordPress actions core on a specific interval, specified by you. The action will trigger when someone visits your WordPress site, if the scheduled time has passed.

Assume that I run a function using wp_schedule_event. Function need 20-30 seconds to finish their task.

So it will affect to the user or not? I mean if it is run in background like normal cron jobs it is not affect to the user.

  • I'm not clear with your question. But, there are plugins like Advanced Cron Manager that can help you assign, display, debug scheduled events. "The action will trigger when someone visits your WordPress site, if the scheduled time has passed." - it means that, wp_cron runs only on user visit, not on server timing (in background). – Mayeenul Islam Oct 27 '16 at 8:10
3

It depends. The initial page load trigger should not but performance may degrade as visitors browse your site until the Cron job is finished.

Is the scheduled event you plan on using PHP or DB intensive? How often will it run?

Here's how it works

  • The scheduled event (aka Cron job) will be initialized once it's due (or past due) by whoever hits your website. So visiting www.test.com/somepage/ will tell Mr. WP-Cron, "Hey dude, it's time to wake up and run this Cron job".
  • If it takes 20-30 seconds to finish and is an intensive DB or PHP task (e.g. lots of DB INSERT or UPDATE statements, or parsing a huge .xml file, etc), there's a good chance the site will be slow for anyone during that time. Especially if you're on shared hosting due to shared CPU and memory.

If it's a Cron job you run once a day or week, I wouldn't worry about the performance hit.

Supporting Answer

  • I found new thing in this answer. wordpress.stackexchange.com/questions/93570/… Please read the last part of this answer (WordPress cron jobs don't make your website slow! part). According to that answer your second point is wrong. Can you please check it? – Damithatt Oct 27 '16 at 8:50
  • 1
    Thx @Damithatt. I read it over and while true that the actual "Cron" may not slow down your site, it's the code you're executing that will affect performance. I've updated my answer and added a supporting link. – cowgill Oct 27 '16 at 9:12
0

I think the question asks if any cron job runs in the "main" PHP worker, the one which is presenting output to the visitor, or it runs in another PHP worker, without "blocking" the visitor thread.

It's easy to find out by experiment.

Try to add an " echo '<h1>Yes, it Runs on this thread</h1>'; " statement somewhere in the start of the cron-job script. If you visit your site then, and you see "Yes, it Runs on this thread" somewhere on your display, then the cron-job runs on your thread.

If you don't, which by the way is what really happens, the cron-job runs in the background (ie in another PHP "worker" when you are using PHP-FPM).

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.