我通过终端在OS X 10.6服务器上运行PHP脚本:
cexa:~ soinro$ php /Volumes/dev1/cron/cron.php
如果脚本有错误,我得到输出:
PHP Notice: Use of undefined constant ccccc - assumed 'ccccc' in /Volumes/dev1/cron/cron.php on line 6
Notice: Use of undefined constant ccccc - assumed 'ccccc' in /Volumes/dev1/cron/cron.php on line 6
PHP Parse error: syntax error, unexpected $end in /Volumes/dev1/http/~dev/_cron/cron.php on line 26
Parse error: syntax error, unexpected $end in /Volumes/dev1/http/~dev/_cron/cron.php on line 26
你可以看到每个通知/错误显示两次:一次为"PHP解析错误",一次为"解析错误"。
我调用的文件是/Volumes/dev1/cron/cron.php
。如果这个文件有一个错误,我只得到"解析错误",但如果它的require
的文件有错误,我得到"PHP解析错误"one_answers"解析错误"的消息。
为什么会发生这种情况,我如何才能使它,以便我得到这两个消息(或只是没有"PHP Parse error"的消息)所有的时间;
为了方便讨论,这里是我调用的原始代码:
ini_set('display_errors', 1);
$crons = array_merge(glob("/Volumes/dev1/http/*/_cron/*"), glob("/Volumes/dev1/http/~dev/*/_cron/*"));
foreach ($crons as $cron):
/* there is only one file in the array */
require_once $cron;
endforeach;
/* this is the endforeach I leave out when I want an error in this file */
下面是require_once
's
$mails = $db->result("select * from newsletter where status = 'sending'");
/* there are 3 elements in $mails */
foreach ($mails as $mail):
echo 'x';
endforeach;
/* this is the endforeach I leave out when I want an error in this file */
非常感谢!!
实际情况是您同时启用了display_errors
和log_errors
当启用log_errors
时,PHP在error_log
ini设置指定的文件中写入错误(不要与log_errors混淆)。如果没有设置error_log
,错误将被写入标准输出,这就是为什么您会看到它们两次。
你必须禁用display_errors和log_errors中的一个;或者将error_log设置为某个文件名(或者设置为syslog如果您想记录为syslog)。