curl_exec maximum execution time - what is causing it? curl_exec maximum execution time - what is causing it? xml xml

curl_exec maximum execution time - what is causing it?


A1:Yes, you got your answer from your 2nd question. it's caused by php's max_execution_time.

A2:It's not safe, unless you are hosting it locally and you know what your script is doing. I think the common practice is either 30sec or max 300sec(5min).

A3If you are dealing with curl, I prefer you to set set_time_limit(0) on very top of your php script(code level equivalent for max_execution_time in php.ini), and use the timeout for curl to handle the timeout.

curl_setopt($curl, CURLOPT_TIMEOUT_MS, 2000); //in miliseconds


  1. The curl to external feed is extremely slow

  2. Is OK to increase the max_execution_time to a higher value, but is not recommended. If the script is to serve as one of your normal web pages, you have to think twice. No user would like to wait for more than 90 seconds to get a page loaded.

  3. Cache it!

Details of cache it! :-

Not a super logic,
what it mean is you can prepare list of the feed URL,
then do a background job (cronjob) to grab each feed URL and store into local storage.
Once the local XML is available, load from local

So, is reverse of on-demand access, get the XML ready before any user would access the page.
The difficulties will be lots of different feed URL to grab, there is an curl_multi_exec which should be ideal to grab multiple url at the same time.