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.

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

报告相同问题?

悬赏问题

  • ¥50 adb连接不到手机是怎么回事?
  • ¥15 vs2022无法联网
  • ¥15 TCP的客户端和服务器的互联
  • ¥15 VB.NET操作免驱摄像头
  • ¥15 笔记本上移动热点开关状态查询
  • ¥85 类鸟群Boids——仿真鸟群避障的相关问题
  • ¥15 CFEDEM自带算例错误,如何解决?
  • ¥15 有没有会使用flac3d软件的家人
  • ¥20 360摄像头无法解绑使用,请教解绑当前账号绑定问题,
  • ¥15 docker实践项目