curl exec仅返回null

时间:2015-08-13 16:45:33

标签: php curl

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已开启

Alse file_get_contents('http://www.google.com/')向我返回错误????

我非常非常困惑。请帮助我:( enter image description here

来自两台服务器的同一时间 enter image description here

并比较两个PHP.ini enter image description here

0 个答案:

没有答案