如何将详细信息写入文件? [英] How to write verbose information into file?

查看:176
本文介绍了如何将详细信息写入文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在php脚本中使用了CURL,我想将CURLOPT_VERBOSE中的信息写入文件中。我尝试了CURLOPT_STDERR,但是没有运气。它仍然在cmd窗口中打印所有内容。我不确定curl_setopt($ ch,CURLOPT_STDERR,$ errFileHandle)中的参数是否;应该是文件处理程序还是文件名(都不起作用)。

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).

推荐答案

在基于Unix的操作系统上运行?在命令行上使用以下命令运行脚本。使用Windows操作系统,请在Cygwin上使用命令。

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);
?>

这篇关于如何将详细信息写入文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆