【问题标题】:How to send arbitrary strings to STDERR via FastCGI wiith PHP?如何使用 PHP 通过 FastCGI 向 STDERR 发送任意字符串?
【发布时间】:2020-09-23 14:18:45
【问题描述】:

我希望我的消息直接出现在我的 NginX 错误日志中,例如

2020/06/04 16:23:00 [error] 9057#9057: *26 FastCGI sent in stderr: "MESSAGE" while reading response header from upstream, client: 151.24.155.27, server: "fqdn", request: "GET /page.php HTTP/2.0", upstream: "fastcgi://127.0.0.1:9000", host: "hostname"

我知道 PHP 在通过 CLI 执行时可以写入 STDERR,但我指的是网页。

【问题讨论】:

  • 不能用error_log函数吗?例如:error_log("This is my message", 0);
  • @WayneWhitty 是的,我刚刚尝试过,它有效,您可以发布像我这样的答案,以便我选择您的。
  • 您可以选择自己的答案!
  • 我的答案是最新的,所以我删除它以避免重复。

标签: php nginx fastcgi stderr


【解决方案1】:

RTFM I guess

这个:

<?php error_log("MESSAGE", 0);?>

结果如下:

2020/06/04 16:23:00 [error] 9057#9057: *26 FastCGI sent in stderr: "MESSAGE" while reading response header from upstream, client: 151.24.155.27, server: "fqdn", request: "GET /page.php HTTP/2.0", upstream: "fastcgi://127.0.0.1:9000", host: "127.0.0.1"

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-08-16
    • 2010-11-22
    • 1970-01-01
    • 2014-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多