Sten
Sten

Reputation: 41

How to write verbose information into file?

I'm using CURL in my php script and I want to write information from CURLOPT_VERBOSE into file. I tried CURLOPT_STDERR but without luck. It still print everything in cmd window. I'm not sure if parameter in curl_setopt($ch, CURLOPT_STDERR, $errFileHandle); should be file handler or file name (both not work).

Upvotes: 4

Views: 5784

Answers (1)

Joseph Lust
Joseph Lust

Reputation: 20015

Running on a Unix based OS? Use the below on the command line to run your script. Using Windows OS, use the command on Cygwin.

php yourPhp.php > yourFile.txt

Or you can just run it in verbose mode with a file handle

<?PHP

$verbosPath = __DIR__.DIRECTORY_SEPARATOR.'verboseOut.txt';
echo "Saving verbose output to: $verbosPath\n";

$handle=curl_init('http://www.google.com/');
curl_setopt($handle, CURLOPT_VERBOSE, true);
curl_setopt($handle, CURLOPT_RETURNTRANSFER, true);
curl_setopt($handle, CURLOPT_STDERR,$f = fopen($verbosPath, "w+"));
curl_exec($handle);

fclose($f);
?>

Upvotes: 4

Related Questions