手册没有说明的是log_errors_max_len仅指的是错误消息的“正文”。这意味着单行错误仍将大于您在此处设置的长度。
为了演示,使用log_errors_max_len=0(0 表示无限制)和log_errors=1 运行此代码:
<?php
// Set your server to these settings:
// error_reporting=-1
// date.timezone=utc ;to suppress the error message "It is not safe to rely on the system's timezone settings."...
echo$msg1; echo$msg2;
发送到error_log 的字节将是:
[15-Jul-2015 01:23:45 utc] PHP Notice: Undefined variable: msg1 in C:\index.php on line 5
[15-Jul-2015 01:23:45 utc] PHP Notice: Undefined variable: msg2 in C:\index.php on line 5
接下来,使用log_errors_max_len=4 和log_errors=1 测试相同的代码。 (记得重启服务器。)error_log 现在是:
[15-Jul-2015 01:23:45 utc] PHP Notice: Unde in C:\index.php on line 5
[15-Jul-2015 01:23:45 utc] PHP Notice: Unde in C:\index.php on line 5
(请注意,您的错误消息前面带有“[15-Jul-2015 01:23:45 utc] PHP Notice:”并附加了“in C:\index.php on line 1”,导致行长于log_errors_max_len 设置的行。)
此问题不仅发生在error_log 中,还发生在发送到客户端的服务器输出中。为了演示,使用log_errors_max_len=4、display_errors=1、html_errors=0、error_prepend_string="PPPP" 和error_append_string="AAAA" 运行上述相同的代码。发送给客户端的输出是:
PPPP
Notice: Unde in C:\index.php on line 5
AAAAPPPP
Notice: Unde in C:\index.php on line 5
AAAA
现在使用 log_errors_max_len=4、display_errors=1、html_errors=1、error_prepend_string="PPPP" 和 error_append_string="AAAA" 运行相同的代码。 (error_prepend_string 和 error_append_string 仅适用于显示的错误,而不适用于记录的错误。)发送到客户端的输出是:
PPPP<br />
<b>Notice</b>: Unde in <b>C:\index.php</b> on line <b>5</b><br />
AAAAPPPP<br />
<b>Notice</b>: Unde in <b>C:\index.php</b> on line <b>5</b><br />
AAAA
另请注意,即使您使用ignore_repeated_errors=0,上述测试也会返回相同的结果。这表明“重复错误”被认为是在错误消息被裁剪之前。
(根据使用的 SAPI,您的结果可能会有所不同。以上测试是在 win 8.1 上使用 php-5.6.7-Win32-VC11-x86 CLI 完成的。)