写给php:// stderr

时间:2012-12-11 23:31:46

标签: php windows xampp stderr

我正在尝试使用php:// stderr来编写日志。我正在使用Slim框架,它使用@fopen('php://stderr', 'w')进行日志记录,并且真的希望它能够正常工作。

以下测试用例应该有效,但只有第一个用于:

// 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手册和谷歌搜索,但没有太多帮助。

特别是,PHP手册on wrappers中的以下引用令人困惑:

  

建议您只使用常量STDIN,STDOUT和STDERR,而不是使用这些[引用php:// stdin,php:// stdout和php:// stderr]包装器手动打开流。“

...给出上面未定义的常量通知。 (我怀疑那些常量可能只用于PHP CLI? - 但我引用的页面没有说明。)

我一直想知道这是否可能是Windows的事情,因为我正在使用PHP 5.3.8开发XAMPP进行开发,但鉴于Google上缺少主题和PHP.net上的评论,我不太确定了。我现在无权访问我的生产服务器日志供我测试。

2 个答案:

答案 0 :(得分:8)

没关系,明白了。我在php://stderrerror_log

之间没有区别

error_log写入PHP错误日志(例如:D:\ xampp \ php \ logs \ php_error_log)

php://stderr写入服务器/ Apache错误日志(例如:D:\ xampp \ apache \ logs \ error.log)

希望这有助于其他人。

答案 1 :(得分:2)

如果您只是运行PHP内置Web服务器(从PHP 5.4.0开始),则php://stderr将输出到启动PHP内置Web服务器的控制台屏幕。