cURL error 28 - Connection timed out after x milliseconds
是的。我知道关于这个错误还有一些类似的问题,但是我已经读完了所有这些内容,但并不能解决我的问题,所以:
我的php代码:
1 2 3 4 5 6 7 8 9 10 11 12 13 | $url = 'example.domain.com/path/file.php' $string = 'param=5'; $ch = curl_init(); // CURL options curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_TIMEOUT, 10); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/x-www-form-urlencoded', 'Content-Length: ' . strlen($string))); curl_setopt($ch, CURLOPT_POSTFIELDS, $string); return curl_exec($ch); |
我以这种方式检查错误:
1 2 3 4 5 6 7 | $curl_errno = curl_errno($ch); $curl_error = curl_error($ch); if($curl_errno > 0) { echo"cURL Error ($curl_errno): $curl_error\ "; } |
请帮助或获得一些我可以检查的线索。
从本地主机或其他服务器上的
是否也可以正常工作(curl或file_get_content)...有任何提示吗?
- 从本地机器我通过php?4sec得到cURL ok响应
- 从服务器(主机服务器)外壳我得到错误7无法连接到example.domain.com端口80:连接超时
-
如果在php中尝试
file_get_contents (来自主机服务器)-无响应 - URL-可从浏览器访问(直接php文件)
-
如果我创建
ajax 请求-响应正常 - 如果我尝试添加到URL http或https-总是相同的错误
- 如果我尝试将限制设置为30秒。同样的结果
您必须增加CURLOPT_TIMEOUT或完全取消cURL执行的超时时间
我遇到了这个问题,这是因为您尝试发送请求的API不能同时接受许多产品的发送。然后,您需要放置PHP sleep函数,以便在每条发送的行之间定义一个范围。在代码中添加