我有这个PHP代码:
error_log('my message 1');
....
error_log('my message 2');
...
error_log('my message 3');
这会在apache error_log中产生包含所有消息的一行:
[Wed Nov 13 17:24:55.880399 2013] [proxy_fcgi:error] [pid xx] [client xxx] AH01071: Got error 'PHP message: my message 1\n'PHP message: my message 2\n'PHP message: my message 3
我的配置:
Apache 2.4
PHP : 5.4
PHP-FPM with proxypassmatch directive.
我的问题:为什么消息在同一行上,如何使每条消息只有一行?
感谢您的回答。
编辑
每封邮件一行应如下所示:
[Wed Nov 13 17:24:55.880399 2013] [proxy_fcgi:error] [pid xx] [client xxx] AH01071: Got error 'PHP message: my message 1'
[Wed Nov 13 17:24:55.880399 2013] [proxy_fcgi:error] [pid xx] [client xxx] AH01071: Got error 'PHP message: my message 2'
[Wed Nov 13 17:24:55.880399 2013] [proxy_fcgi:error] [pid xx] [client xxx] AH01071: Got error 'PHP message: my message 3'
最佳答案
error_log("error message \r\n");
PHP忽略单引号内的特殊ASCII字符(它将其呈现为单独的字符),您需要使用双引号。
此外:
您应该打开php.ini文件,该文件位于/ etc / php5 / apache2 /文件夹中,并更改
error_log
指令以指向文件。Apache具有足够的特权可以写入该文件,这一点很重要。
所以
chown www-data:www-data /var/www/somefile.log
应该做如果当前未定义,则日志将通过syslog,并且不允许出现新行。
附加编辑:
要渗透输出缓冲,您需要引发一个异常。
例:
try{
ob_start();
doSomething($userInput);
ob_end_flush();
}
catch(Exception $e){
error_log($e->getMessage());
}
function doSomething($data = null){
if($data === null){
throw new Exception("Data is required");
}
else{
//do something
}
}