[英]PHP Curl request increase timeout
I have this php code that consumes an api. 我有消耗api的此php代码。 I have one request that takes a long time almost 4 minutes.
我有一个要求,要花很长时间将近4分钟。 The
curl
request times out and returns an empty response. curl
请求超时并返回空响应。
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);
I had this error too and had to change directly the default_socket_timeout
in the php.ini
file. 我也有此错误,必须直接更改
php.ini
文件中的default_socket_timeout
。 After that, you have to reload Apache and it should work. 之后,您必须重新加载Apache,它应该可以工作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.