我使用PHP下载一个页面如下,它可以工作(在我的开发计算机和我们的生产PHP服务器中):
$url = "http://google.com/";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
$content = curl_exec($ch);
curl_close($ch);
echo strlen($content);
但是,对于网址“https://invue.com/patents/”,它只适用于我的开发计算机,但不适用于生产PHP服务器(strlen($content)
返回0
)。
知道可能出现什么问题,或者如何找出问题?
答案 0 :(得分:1)
对于卷曲失败,您可以使用函数curl_error
$url = "http://google.com/";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
$content = curl_exec($ch);
// check, Did something go wrong !?
if($content === false){
// This will show what's wrong.
echo 'Curl error: ' . curl_error($ch);
}
curl_close($ch);
echo strlen($content);
有关curl_error
的更多信息