tags:

views:

49

answers:

2

Hello,

My question revolves around the use of curl_multi_exec in PHP. I am using code similar to the example shown on this link: http://www.rustyrazorblade.com/2008/02/curl_multi_exec/

With about 10 URLs to execute, I sometimes come across the error message: Fatal error: Maximum execution time of 30 seconds exceeded in... This message points to the curl_multi_exec line in the code.

I need to continue processing in spite of this and also use means to keep a note of which URL failed to execute.

Can someone help me handle this situation?

Thanks!

A: 

If you have access to your php.ini file, you can increase the max_execution_time setting. This is the time in seconds a PHP script is alowed to run.

JochenJung
I still want to keep a limit of 30 seconds on the execution time, and identify which URLs are exceeding the time limit, so I won't use this option.
Jon
A: 

I would try having a parent process which forks out children processes. The parent process is able to wait till the child is done and can see the exit code of the child. So if the url was processed successfully then it would have an exit code of 0, otherwise a nonzero represents an error.

The parent process will still need to have a longer max_execution_time setting which can be set within the script itself, while the children have a max_execution_time setting of 30 seconds.

Here is how to fork with PHP http://www.electrictoolbox.com/article/php/process-forking/

You can set the parent's max_execution_time like this

set_time_limit ( 0 )

0 will allow the script to run without a time limit.

Just a side note about child processes, a child process must be allowed to finish before killing the parent, otherwise you can have zombie processes with no one owning them.

David Young
Isn't there a more direct way to know that the curl_multi_exec operation has timed out for the concerned URL?I get a feeling there should be a means of denoting failure by means of updating a variable somewhere to indicate that.
Jon