errorno(), but cURL is installed and works

I am trying to get at the cURL error number, but the curl_errorno() function doesn't seem to work. If I make a one-line script:

curl_errorno();

I get this error:

Call to undefined function curl_errorno()...

  • cURL is installed... I can use it to make requests just fine.
  • PHP 5.3.6 (as reported by php.ini)
  • cURL 7.19.7 (as reported by php.ini)
  • My configure command contained --with-curl
  • Any thoughts as to why curl_errorno() isn't available?


    curl_errno(); 
    

    curl_errorno(); 
    

    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;
    }
    

    To use it...

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

    Maybe give that a try, if it works, maybe its an issue with your previous code?


    如果您有任何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;
    }
    
    链接地址: http://www.djcxy.com/p/57744.html

    上一篇: 使用PHP的round()函数中的PHP 5.3.4可能的错误

    下一篇: errorno(),但cURL已安装并可用