3

我正在尝试将 curl VERBOSE 信息保存到字符串中。这是我到目前为止尝试过的

curl_setopt($ch, CURLOPT_VERBOSE, true);
$fp = fopen("php://memory", 'w+'); //also tried temp
curl_setopt($ch, CURLOPT_STDERR, $fp);
$ret = curl_exec($ch);
rewind($fp);
$verbose = stream_get_contents($fp);
echo "Verbose: ".$verbose;

$verbose 包含一个空值

添加

fputs($fp, "test"); //works if I manually put test string

有效,因此输出清楚地可写,并且 stream_get_contents 是正确的功能

我在这里想念的是什么?

谢谢

PS请不要让我为此使用临时文件。我正在寻找一种正确的方式来处理 IO 流

编辑

$outputStream = fopen("php://output", 'w');
curl_setopt($ch, CURLOPT_STDERR, $outputStream);
ob_start();
$ret = curl_exec($ch);
$verbose = ob_get_contents();       
ob_end_clean();
fclose($outputStream);
curl_close($ch);
echo "Verbose: ".$verbose;

这也不起作用,因为 php://output 由于某种原因无法被 ob_buffer 捕获(错误?)

4

0 回答 0