Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I have a task scheduled to run daily using wp-cron. The task takes over a minute to run (between downloading and parsing a very large file with cURL). According to the WP documentation,

"The action will trigger when someone visits your WordPress site, if the scheduled time has passed."

Could this "someone" have to wait the full minute for my script to run while trying to access my site, or are wp-cron tasks asynchronous?

share|improve this question
add comment

1 Answer

up vote 2 down vote accepted

No, the WP-Cron tasks run asynchronously from the viewing user. They should not see any delay.

Although if your task takes more than a minute, it may never finish since most hosts are setup to kill PHP processes after 30 seconds.

share|improve this answer
    
I'm using set_time_limit to bypass the 30 second default (thanks). Do two independent wp-cron tasks run asynchronously from eachother? In other words, if there's an error (such as a timeout) on one, will the other fail to launch? –  adamdport Sep 11 '12 at 16:50
    
The wp-cron process gets launched and runs all pending tasks until it's done, basically. Only one wp-cron process should run at a time. So it's asynchronous from the viewer of the site, but synchronous with the various tasks. Also, set_time_limit may not work on some (most) web hosts. –  Otto Sep 11 '12 at 17:22
    
So if a single cron task has an error (such as the timeout we keep talking about), any remaining scheduled tasks will fail to run? –  adamdport Sep 11 '12 at 17:31
1  
Until the task succeeds, yeah, probably. Don't write cron tasks that can fail or cause timeouts. –  Otto Sep 11 '12 at 17:36
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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