[英]curl exec return null only
PHP代碼
function file_get_contents_curl($url) {
try {
$ch = curl_init();
if (FALSE === $ch)
throw new Exception('failed to initialize');
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); //Set curl to return the data instead of printing it to the browser.
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
$content = curl_exec($ch);
if (FALSE === $content)
throw new Exception(curl_error($ch), curl_errno($ch));
return $content;
} catch(Exception $e) {
trigger_error(sprintf(
'Curl failed with error #%d: %s',
$e->getCode(), $e->getMessage()),
E_USER_ERROR);
}
}
我稱這個函數為var_dump(file_get_contents_curl("http://www.google.com"));die;
但這返回的只是null; 我在具有相同配置的其他服務器上運行了此代碼,並正常工作,
allow_url_fopen
已開啟
還可以file_get_contents('http://www.google.com/')
向我返回false file_get_contents('http://www.google.com/')
????
您可能有防火牆限制,或者無法訪問互聯網
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.