Make cURL output STDERR to file (or string)

后端 未结 6 1954
醉话见心
醉话见心 2020-12-03 11:30

We\'re trying to debug some cURL errors on the server, and I would like to see the STDERR log. Currently, all we can see for our error is \"error code: 7\" and that we can\'

6条回答
  •  执念已碎
    2020-12-03 12:04

    I needed to close the file before being able to read it, this worked for me:

    $filename = 'curl.txt';
    $curl_log = fopen($filename, 'w'); // open file for write (rw, a, etc didn't help)
    curl_setopt($ch, CURLOPT_VERBOSE, 1);
    curl_setopt($ch, CURLOPT_STDERR, $curl_log);        
    
    $result = curl_exec($ch);
    
    fclose($curl_log);      
    $curl_log = fopen($filename, 'r'); // open file for read
    $output= fread($curl_log, filesize($filename));
    echo $output;
    

    (PHP 5.6.0, Apache/2.2.15)

提交回复
热议问题