Reputation: 5663
I have this php code that consumes an api. I have one request that takes a long time almost 4 minutes. The curl
request times out and returns an empty response.
I found this solution.
ini_set('max_execution_time', 0);
curl_setopt($ch, CURLOPT_TIMEOUT, 0);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 0);
But this doesn't have any effect.
How do I wait for the request to finish execution. Here is full snippet.
ini_set('max_execution_time', 0);
curl_setopt($ch,CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_FRESH_CONNECT, true);
curl_setopt($ch, CURLOPT_TIMEOUT, 0);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 0);
$response = curl_exec($ch);
$httpCode = curl_getinfo($ch,CURLINFO_HTTP_CODE);
curl_close($ch);
Upvotes: 0
Views: 4854
Reputation: 58
I had this error too and had to change directly the default_socket_timeout
in the php.ini
file. After that, you have to reload Apache and it should work.
Upvotes: 1