curl, fopen & file_get_contents 在浏览器中随机抛出"The connection was reset"错误



我试过3,file_get_contents, curl &fopen,但问题是我得到"连接被重置"错误随机,我的意思是,如果它适用于url A,但与url b失败

如有任何帮助,不胜感激。

下面是代码:
function readRemoteFile($url, $use = FOP) {
$url = urldecode($url);
switch ($use) {
    case FOP:
        $handle = fopen($url, 'r');
        while (!feof($handle)) {
            $content.=fread($handle, 2048);
        }
        return $content;
        break;
    case FGC :
        if (!$handle = file_get_contents($url)) { 
            return FALSE;
        } else {
            while ($chunk = fread($handle, 2048)) {
                $content .= $chunk;
            }
            fclose($handle);
            return $content;
        }
        break;
    case CURL :
        $ch = curl_init(urldecode($url));
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        ob_start ();
        $c = curl_exec($ch);
        curl_close($ch);
        ob_end_clean ();
        return trim($c);
        break;
}

}

认为,

This:

case FGC :
    if (!$handle = file_get_contents($url)) { 
        return FALSE;
    } else {
        while ($chunk = fread($handle, 2048)) {
            $content .= $chunk;
        }
        fclose($handle);
        return $content;
    }

是错误的。应该是:

case FGC :
  return file_get_contents($url);

相关内容

  • 没有找到相关文章

最新更新