Search code examples
phpnginxfastcgistderr

How to send arbitrary strings to STDERR via FastCGI wiith PHP?


I would like my message to appear directly in my NginX error log, like

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"

I know that PHP can write to STDERR when executed via CLI, but I'm referring to a webpage.


Solution

  • RTFM I guess.

    This:

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

    ends up like this:

    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"