Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 为什么curl在本地工作,但在我的web托管中失败了?_Php_Json_Curl_Web Hosting - Fatal编程技术网

Php 为什么curl在本地工作,但在我的web托管中失败了?

Php 为什么curl在本地工作,但在我的web托管中失败了?,php,json,curl,web-hosting,Php,Json,Curl,Web Hosting,我有以下代码: $jsonurl = "http://ipinfo.io"; $ch = curl_init($jsonurl); curl_setopt($ch, CURLOPT_TIMEOUT, 5); curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_HEAD

我有以下代码:

    $jsonurl = "http://ipinfo.io";
    $ch = curl_init($jsonurl);
    curl_setopt($ch, CURLOPT_TIMEOUT, 5);
    curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_HEADER, 0);
    $predata = curl_exec($ch);
    var_dump(curl_error($ch));
    curl_close($ch);       
    $data = json_decode($predata, true);
它在本地运行得很好,但当我将其上传到我的web主机时,我有:

string(20) "connect() timed out!" 
我的网络主机中的phpinfo说:

URL support enabled
cURL Information    libcurl/7.19.7 NSS/3.14.0.0 zlib/1.2.3 libidn/1.18 libssh2/1.4.2
你能不能给我一些线索,看看问题出在哪里


谢谢

不确定,但是,您的ip可能会被远程服务器阻塞

或者您需要更多的时间,请尝试添加此

curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, 5);
curl_setopt($ch, CURLOPT_TIMEOUT, 400);
到你的代码

注意:CURLOPT_CONNECTTIMEOUT设置为零表示无超时

卷发超时

允许cURL函数执行的最大秒数

CURLOPT_连接超时

尝试连接时等待的秒数。使用0无限期等待


希望这些帮助增加连接超时时间?可能只是速度很慢。谢谢,但我添加了400,但它不起作用:(