【问题标题】:How to write PHP errors to stderr?如何将 PHP 错误写入标准错误?
【发布时间】:2014-08-27 07:11:35
【问题描述】:

如何更改 php-fpm.conf(或 php.ini),以便将所有错误/警告/...写入标准错误(或替代标准输出)?

我运行 php5-fpmdaemonize = no 并希望在我的终端中查看所有错误。

【问题讨论】:

    标签: logging stdout php stderr


    【解决方案1】:

    我认为您无法做到这一点,至少在我从您的问题中理解的方式上。

    我会建议你通过终端实时查看 php

    第 1 步 - 将所有错误写入文件

    更改您的 php.ini 文件以将每个错误写入文件 /logs/phpLogs

    第 2 步 - 通过错误“实时”使用tail

    从命令行运行 tail 命令 tail -f /logs/phpLogs

    第 3 步 - 可选择使用error_log

    使用 php error_log 命令 error_log(print_r(debug_backtrace(), true ))

    EDIT:(刚刚找到)我的anwser类似于How to log errors and warnings into a file

    【讨论】:

      【解决方案2】:

      解决办法是设置...

      ; Redirect worker stdout and stderr into main error log. If not set, stdout and
      ; stderr will be redirected to /dev/null according to FastCGI specs.
      ; Note: on highloaded environement, this can cause some delay in the page
      ; process time (several ms).
      ; Default Value: no
      catch_workers_output = yes
      

      【讨论】:

        【解决方案3】:

        是的,可以不用弄乱 .ini 配置。


        使用Unix descriptor,例如其中一个示例:

        php myscript.php 2> errors.log
        

        或者通过使用 hashbang,文件必须设置为可执行文件:

        ./myscript 2> errors.log
        

        从那里记录所有错误。


        要仅在 errors.log 中写入,请在 php 脚本中的任何位置使用 fwrite

        <?php
        fwrite(STDERR, "Some debug infos\n");
        

        仅出现在errors.log。在编写快速刷新脚本时很有用。

        请注意,重新启动时会清除所有错误。


        要查看错误,请使用 tail -fwatch cat

        watch cat errors.log
        

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 2011-06-27
          • 1970-01-01
          • 1970-01-01
          • 2012-10-19
          • 2017-06-10
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多