我试图打开一个外部网址。它在我的本地服务器上运行良好。但是当我搬到实时服务器时,它显示超时错误。当我用同一域中的 url 替换 url 时,它工作正常。
allow_url_fopen 在服务器中为 ON。
<?php
if ($fp = fopen('https://www.google.com/', 'r')) {
$content = '';
// keep reading until there's nothing left
while ($line = fread($fp, 1024)) {
$content .= $line;
}
echo $content;
echo 'do something with the content here';
// ...
} else {
echo 'an error occured when trying to open the specified url';
}
?>
更新
$curl_handle=curl_init();
curl_setopt($curl_handle,CURLOPT_URL,'https://www.google.co.in/');
curl_setopt($curl_handle,CURLOPT_CONNECTTIMEOUT,2);
curl_setopt($curl_handle,CURLOPT_RETURNTRANSFER,1);
$buffer = curl_exec($curl_handle);
curl_close($curl_handle);
if (empty($buffer)){
print "Nothing returned from url..<p>";
}
else{
print $buffer;
}
我也试过卷曲。它返回“没有从 url 返回 ..”。但它在我的本地和演示服务器上运行良好。