PHP cURL致命错误:未捕获的异常错误

时间:2018-11-25 19:58:01

标签: php xml

我正在尝试使用PHP cURL检索远程服务器上的XML文件。在我的个人计算机上使用PHP v5.5(使用Windows / MSVC11(Visual C ++ 2012)作为编译器)并在浏览器中运行以下代码时,文件aqi.xml保存到我的PHP文件所在的文件夹中,这是唯一的单词“下载!”打印到浏览器。

ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);

$fileUrl = 'http://www.southwestohioair.org/UserFiles/Servers/Server_3788196/File/EnvironmentalServices/AirQuality/Feeds/feed_aqi.xml';
$saveTo = 'aqi.xml';

$fp = fopen($saveTo, 'w+');
if($fp === false){
    throw new Exception('Could not open: ' . $saveTo);
}
$ch = curl_init($fileUrl);
curl_setopt($ch, CURLOPT_FILE, $fp);
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
curl_setopt($ch,CURLOPT_USERAGENT,'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.13) Gecko/20080311 Firefox/2.0.0.13');
curl_exec($ch);
if(curl_errno($ch)){
    throw new Exception(curl_error($ch));
}
$statusCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);

if($statusCode == 200){
    echo 'Downloaded!';
} else{
    echo "Status Code: " . $statusCode;
}

但是,当我在Web服务器上运行相同的PHP脚本(在Apache上使用PHP v7.1.18)时,将在浏览器中显示以下内容:

Fatal error: Uncaught Exception: Failed connect to www.southwestohioair.org:80; Connection timed out in /storage/ssd5/010/1116010/public_html/sandbox/curlaqitest.php:25 Stack trace: #0 {main} thrown in /storage/ssd5/010/1116010/public_html/sandbox/curlaqitest.php on line 25

我是否有任何原因或设置缺失,阻止我的Apache服务器在本地计算机上成功运行后无法成功检索该文件?

0 个答案:

没有答案