dpzp5127 2012-08-12 10:47
浏览 177
已采纳

在ubuntu中启用php-curl功能

I'm trying something with curl in php.

I read about the use of CURLOPT_VERBOSE to help debugging. But it gives no output. I checked my phpinfo() and under cURL stands:

debug => no

I guess that is the problem here. How can I set this to yes? I looked in php.ini and could find it.

Also no luck on google. also no luck here: How to enable features for php-curl

I hope someone can help me!

  • 写回答

1条回答 默认 最新

  • dqkf49487 2012-08-17 21:44
    关注

    Having a debug build of cURL isn't required for the CURLOPT_VERBOSE setting to work, but by default CURLOPT_VERBOSE information gets output to STDERR which is only visible on the console. So if you are running PHP from a browser, the verbose output isn't sent anywhere you can see.

    You can set the option CURLOPT_STDERR to a file handle and the verbose output should be written there.

    You should be able to do this:

    $stdout = fopen('php://output', 'w+');
    
    $ch = curl_init(); 
    curl_setopt($ch, CURLOPT_URL, 'http://www.example.com');
    curl_setopt($ch, CURLOPT_VERBOSE, 1);
    curl_setopt($ch, CURLOPT_STDERR, $stdout);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    
    $data = curl_exec($ch);
    

    I'm not sure if I'm encountering a PHP bug at the moment (running PHP 5.4.5 via FastCGI) because I don't see the verbose output in the browser, but if I run it from the command line I do. If I fwrite to $stdout I do see that output in the browser but still nothing from cURL so I know the handle is valid.

    If you experience the same issue, here is a workaround:

    $tempout = fopen('php://temp', 'w+');
    
    $ch = curl_init(); 
    curl_setopt($ch, CURLOPT_URL, 'http://www.example.com');
    curl_setopt($ch, CURLOPT_VERBOSE, 1);
    curl_setopt($ch, CURLOPT_STDERR, $tempout);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    
    $data = curl_exec($ch);
    
    rewind($tempout);
    $debug = stream_get_contents($tempout);
    
    echo $debug; // the data from CURLOPT_VERBOSE
    

    Hope that helps.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥65 永磁型步进电机PID算法
  • ¥15 sqlite 附加(attach database)加密数据库时,返回26是什么原因呢?
  • ¥88 找成都本地经验丰富懂小程序开发的技术大咖
  • ¥15 如何处理复杂数据表格的除法运算
  • ¥15 如何用stc8h1k08的片子做485数据透传的功能?(关键词-串口)
  • ¥15 有兄弟姐妹会用word插图功能制作类似citespace的图片吗?
  • ¥200 uniapp长期运行卡死问题解决
  • ¥15 latex怎么处理论文引理引用参考文献
  • ¥15 请教:如何用postman调用本地虚拟机区块链接上的合约?
  • ¥15 为什么使用javacv转封装rtsp为rtmp时出现如下问题:[h264 @ 000000004faf7500]no frame?