Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/282.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 获得;康涅狄格州拒绝;并显示相应的例外情况_Php_Exception_Curl - Fatal编程技术网

Php 获得;康涅狄格州拒绝;并显示相应的例外情况

Php 获得;康涅狄格州拒绝;并显示相应的例外情况,php,exception,curl,Php,Exception,Curl,我有以下功能来查看流是联机的还是脱机的: function remoteFileExists($url) { $curl = curl_init($url); curl_setopt($curl, CURLOPT_NOBODY, true); curl_setopt($curl, CURLOPT_TIMEOUT,1000); $result = curl_exec($curl); $ret = false; if ($result !== fals

我有以下功能来查看流是联机的还是脱机的:

function remoteFileExists($url) {
    $curl = curl_init($url);
    curl_setopt($curl, CURLOPT_NOBODY, true);
    curl_setopt($curl, CURLOPT_TIMEOUT,1000);
    $result = curl_exec($curl);
    $ret = false;
    if ($result !== false) {
        $statusCode = curl_getinfo($curl, CURLINFO_HTTP_CODE);  
        if ($statusCode == 200) {
            $ret = $url;   
        }
    }else{
         throw new Exception("img/webcam-offline.jpg");
    }
    curl_close($curl);
    return $ret;
}
我现在用foreach()来讨论它们
try{
   $imgSrc = remoteFileExists($protocol.$device_protection.$ip.":".$port."/".$deviceStream);
}catch(Exception $e){
   $imgSrc = $e->getMessage();
}

这个很好用。但在一台计算机上,可能是防火墙导致了“加载资源失败:net::ERR_CONNECTION_densed”。在这台计算机上,它不显示脱机图像,有什么方法也能捕捉到吗?

net::ERR\u CONNECTION\u densed
是javascript/Chrome错误,不是吗?我不确定这与你发布的PHP有什么关系?是的,你是对的,Chrome是唯一一个真正显示错误的浏览器,FF和IE只是不加载流并显示“缺少图像”图标。然而,在电话和其他几台电脑上,一切都很好。我不想修复错误本身,我只想显示一条特定的错误消息。。。