写入 php://stderr [英] Writing to php://stderr
问题描述
我正在尝试使用 php://stderr 来编写日志以使其工作.我正在使用 Slim 框架,它利用 @fopen('php://stderr', 'w')
进行日志记录,并且真的希望它能够工作.
I'm trying to get the use of php://stderr for writing logs to work. I'm using Slim framework which makes use of @fopen('php://stderr', 'w')
for logging and really want this to work.
以下测试用例应该可以工作,但只有第一个可以:
The following test cases should work but only the first one does:
// 1. error_log - works fine
error_log("Written through the error_log function", 0);
// 2. PHP wrapper, ie php://stderr - does not work
$stderr = fopen( 'php://stderr', 'w' );
fwrite($stderr, "Written through the PHP error stream" );
fclose($stderr);
// 3. PHP wrapper also, different syntax, just to be safe - no effect either
file_put_contents( "php://stderr","Hello World" );
// 4. PHP wrapper, this time using this elusive constant referred to in the manual - result: "Notice: Use of undefined constant STDERR - assumed 'STDERR' ", ie: failed also!
file_put_contents( STDERR, "Hello World" );
我一直在查看 PHP 手册和谷歌搜索,但没有太多帮助.
I've been looking through the PHP manual and Googling a lot but without much help.
特别是,PHP 手册关于包装器的以下引用令人困惑:
In particular, the following quote from the PHP manual on wrappers is confusing:
建议您只使用常量 STDIN、STDOUT 和 STDERR,而不是使用这些 [引用 php://stdin、php://stdout 和 php://stderr] 包装器手动打开流."
It is recommended that you simply use the constants STDIN, STDOUT and STDERR instead of manually opening streams using these [referring php://stdin, php://stdout and php://stderr] wrappers."
...鉴于上面未定义的常量通知.(我怀疑这些常量可能仅用于 PHP CLI?-但我引用的页面没有说明.)
...given the undefined constant notice above. (I suspect those constants might be for use with PHP CLI -only?- but the page I'm citing does not state it.)
我一直想知道这是否可能是 Windows 的事情,因为我正在运行带有 PHP 5.3.8 的 XAMPP 进行开发,但鉴于 Google 上缺乏主题和 PHP.net 上的评论,我不太确定了.我现在无权访问我的生产服务器日志以供我测试.
I've been wondering if this could be a Windows thing as I'm running XAMPP with PHP 5.3.8 for development but given the lack of topics on Google and the comments on PHP.net, I'm not so sure anymore. I do not have access to my production server logs right now for me to test out.
推荐答案
没关系,明白了.我不太明白 php://stderr
和 error_log
之间的区别:
Never mind, got it. I did not quite get the difference between php://stderr
and error_log
:
error_log
写入 PHP 错误日志(例如:D:\xampp\php\logs\php_error_log)
error_log
writes to the PHP error log (eg: D:\xampp\php\logs\php_error_log)
php://stderr
写入服务器/Apache 错误日志(例如:D:\xampp\apache\logs\error.log)
php://stderr
writes to the server/Apache error log (eg: D:\xampp\apache\logs\error.log)
希望这对其他人有所帮助.
Hopefully this helps someone else.
这篇关于写入 php://stderr的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!