我正在尝试调试这个
cURL
操作。 var_dump()
正在回归 bool(false)
在这种情况下我怎样才能让它退出尝试?
function parse($url, $headonly = TRUE ){
$agents = 'Mozilla/5.0 (X11; U; Linux i686; en-US) AppleWebKit/534.16 (KHTML, like Gecko) Chrome/10.0.648.204 Safari/534.16';
try
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_VERBOSE, FALSE);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
curl_setopt($ch, CURLOPT_USERAGENT, $agents);
curl_setopt($ch, CURLOPT_URL, $url);
$curlResp = curl_exec($ch);
curl_close($ch);
var_dump($curlResp); //RETURNS bool(false)
die;
$resp = str_replace("class=l","class='l'",$curlResp);
return $resp;
}
catch( Exception $e)
{
$strResponse = "";
$strErrorCode = $e->getCode();
$strErrorMessage = $e->getMessage();
print_r($arrCurlInfo, $strErrorCode, $strErrorMessage);
die;
} //end catch
}
为什么不尝试在返回 false 时抛出异常?
即
if ($curlResp === FALSE) {
throw new Exception();
}