簡體   English   中英

curl exec僅返回null

[英]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/') ????

我非常非常困惑。請幫助我:( 在此處輸入圖片說明

來自兩個服務器的相同時間 在此處輸入圖片說明

並比較兩個PHP.ini 在此處輸入圖片說明

您可能有防火牆限制,或者無法訪問互聯網

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM