在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!

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.