调用未定义的函数curl_errorno(),但是cURL已安装并正常工作

时间:2012-02-21 17:06:52

标签: php curl php-5.3 libcurl

我正在尝试获取cURL错误号,但curl_errorno() function似乎不起作用。如果我制作单行剧本:

curl_errorno();

我收到此错误:

  

调用未定义的函数curl_errorno()...

  • 安装了cURL ......我可以用它来提出请求。
  • PHP 5.3.6(由php.ini报告)
  • cURL 7.19.7(由php.ini报道)
  • 我的配置命令包含--with-curl

关于为什么curl_errorno()不可用的任何想法?

3 个答案:

答案 0 :(得分:8)

curl_errno(); 

curl_errorno(); 

答案 1 :(得分:0)

http://www.jonasjohn.de/snippets/php/curl-example.htm

function curl_download($Url){

    // is cURL installed yet?
    if (!function_exists('curl_init')){
        die('Sorry cURL is not installed!');
    }

    // OK cool - then let's create a new cURL resource handle
    $ch = curl_init();

    // Now set some options (most are optional)

    // Set URL to download
    curl_setopt($ch, CURLOPT_URL, $Url);

    // Set a referer
    curl_setopt($ch, CURLOPT_REFERER, "http://www.example.org/yay.htm");

    // User agent
    curl_setopt($ch, CURLOPT_USERAGENT, "MozillaXYZ/1.0");

    // Include header in result? (0 = yes, 1 = no)
    curl_setopt($ch, CURLOPT_HEADER, 0);

    // Should cURL return or print out the data? (true = return, false = print)
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

    // Timeout in seconds
    curl_setopt($ch, CURLOPT_TIMEOUT, 10);

    // Download the given URL, and return output
    $output = curl_exec($ch);

    // Close the cURL resource, and free system resources
    curl_close($ch);

    return $output;
}

使用它......

print curl_download('http://www.example.org/');

也许尝试一下,如果它有效,可能是你之前代码的问题?

答案 2 :(得分:-1)

如果您有任何CURL或CURL扩展问题,请不要在您的服务器上安装,只需使用以下代码

function get_web_page( $url )
{
    $options = array( 'http' => array(
        'user_agent'    => 'spider',    // who am i
        'max_redirects' => 10,          // stop after 10 redirects
        'timeout'       => 120,         // timeout on response
    ) );
    $context = stream_context_create( $options );
    $page    = @file_get_contents( $url, false, $context);

    $result  = array( );
    if ( $page != false )
        $result['content'] = $page;
    else if ( !isset( $http_response_header ) )
        return null;    // Bad url, timeout

    // Save the header
    $result['header'] = $http_response_header;

    // Get the *last* HTTP status code
    $nLines = count( $http_response_header );
    for ( $i = $nLines-1; $i >= 0; $i-- )
    {
        $line = $http_response_header[$i];
        if ( strncasecmp( "HTTP", $line, 4 ) == 0 )
        {
            $response = explode( ' ', $line );
            $result['http_code'] = $response[1];
            break;
        }
    }

    return $result;
}