I’m trying to debug a curl session but I can’t seem to read the data from the file created. In the code below, file_get_contents returns false and a blank page shows up:
<?php
$curl = curl_init();
curl_setopt ($curl, CURLOPT_URL, "http://www.php.net");
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_VERBOSE, 1);
$fh= fopen('test.txt', 'w+');
curl_setopt($curl, CURLOPT_STDERR, $fh );
curl_exec($curl);
fclose($fh);
curl_close($curl);
echo file_get_contents("test.txt");
?>
however when I use the code:
<?php
echo file_get_contents("test.txt");
?>
the content in the text file displays just fine.
The option
CURLOPT_RETURNTRANSFERset toTRUEmakes curl returns its output as a string, but your code is not storing that output in any variable. Try something like this:Other problem is that
CURLOPT_STDERRsets a location to output errors, not the actual transfer.