Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Curl timeout when downloading xml

Tags:

php

curl

xml

So, I try to get xml-file with curl from url. Thing is, file is generated on demand via script, which takes up to 80-100 seconds and so my curl is falling off with timeout error.

url looks something like this:

https://domain/mancgi/report?params&out=xml

I tried to set CURLOPT_TIMEOUT and CURLOPT_CONNECTTIMEOUT, and also set_time_limit() for script itself(which works fine), but nothing's changed - still timeout.

Curl code looks like this:

set_time_limit(1000);
$curl = curl_init($url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE); 
curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 0); 
curl_setopt($curl, CURLOPT_TIMEOUT, 300); 
$xml = curl_exec($curl);

Anyone has any ideas?

like image 600
user976258 Avatar asked Nov 13 '22 16:11

user976258


1 Answers

I believe you may be hitting the default_socket_timeout in the php.ini which is 60 seconds by default.

Try changing and see if it works. If not, try this instead.

$xml = file_get_contents($url);

Doing this will use wrappers which you can read about here: http://php.net/manual/en/wrappers.php

And you will need to also ensure that the required wrappers for use by file_get_contents are enabled in php.ini (which are usually enable so you should be ok, but just check to make sure).

Using that may bypass the timeout you are experiencing if the timeout is enforced by CURL and remember to adjust the default_socket_timeout in php.ini FROM 60 SECONDS to something else which i believe may be your problem

The INI Settings To Check

http://php.net/manual/en/filesystem.configuration.php

like image 57
HenchHacker Avatar answered Nov 15 '22 04:11

HenchHacker