php curl_exec returns empty


php curl_exec returns empty

 $ch = curl_init();
 curl_setopt($ch, CURLOPT_URL, $url);
 curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
 curl_setopt($ch, CURLOPT_PROXY, $proxy); // $proxy is ip of proxy server
 curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
 curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
 curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10);
 curl_setopt($ch, CURLOPT_TIMEOUT, 10);
 $httpCode = curl_getinfo($ch , CURLINFO_HTTP_CODE); // this results 0 every time
 echo '<br> curl'.$ch; //this line outputs resource id#5
 $exec = stripslashes(curl_exec($ch)); 
 echo '<br> exec'.curl_exec($ch); //this results blank

我很困惑为什么$exec不返回任何东西,我是卷曲新手请帮忙,提前谢谢

curl_exec将在请求失败时返回false。将您的函数调整为此:

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_PROXY, $proxy); // $proxy is ip of proxy server
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10);
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
$httpCode = curl_getinfo($ch , CURLINFO_HTTP_CODE); // this results 0 every time
$response = curl_exec($ch);
if ($response === false) 
    $response = curl_error($ch);
echo stripslashes($response);
curl_close($ch);

这样你会看到卷曲错误

您正在尝试在实际进行 HTTP 调用之前访问 HTTP 响应代码。反向执行,如下所示:

$response = curl_exec($ch);
$httpCode = curl_getinfo($ch , CURLINFO_HTTP_CODE); // this results 0 every time

尝试:

curl_setopt($ch, CURLOPT_TIMEOUT, 50);

也许响应超过 10。

有同样的问题,我像这样解决。

结果返回 0 表示您无法连接到服务器,因此请重新检查您的代理并增加超时:)