如何更改 php-fpm.conf(或 php.ini),以便将所有错误/警告/...写入 stderr(或 stdout)?
我用
php5-fpm
运行 daemonize = no
并希望查看终端中的所有错误。
解决方案是设置...
; 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
是的,可以在不弄乱 .ini 配置的情况下实现。
使用 Unix 描述符,如以下示例之一:
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 -f
或 watch cat
watch cat errors.log
我认为你无法实现这一目标,至少从我从你的问题中理解的方式来看是这样。
我会建议您解决通过终端实时查看 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 ))
编辑:(刚刚找到)我的答案与如何将错误和警告记录到文件中
类似