I just noticed that if you run a php script command line that uses curl with the CURLOPT_VERBOSE parameter, you cannot capture the output ...
Example:
$php myscript.php > logfile.txt 2>&1
All PHP output will go into the log file, but the failure will still hit the screen.
How can I capture PHP output with curl output?
$ch = curl_init();
curl_setopt($ch, CURLOPT_VERBOSE, TRUE);
curl_setopt($ch, CURLOPT_USERAGENT, $this->agentString);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
$data = curl_exec($ch);
curl_close($ch);
Edit:
Adding a line
curl_setopt($ch, CURLOPT_STDERR, STDOUT);
This seems to be a trick. However, now it seems that the output of curl conflicts with the output of php and overwrites the log file with its own output. Weird!
Edit 2:
It works
$php myscript.php >> logfile.txt 2>&1
source
share