PHP Error log file format (php.ini error_log directive) on Windows

Sergey L picture Sergey L · Jun 12, 2011 · Viewed 32.6k times · Source

For an example:
php.ini file

...
; Log errors to specified file.
error_log = c:/php/php.log
...

Error log file (c:/php/php.log) contains every entry in this format:

[12-Jun-2011 12:58:55] PHP Notice:  Undefined variable: test in C:\www\phpinfo.php on line 2\r\r\n
[12-Jun-2011 12:59:01] PHP Notice:  Undefined variable: test in C:\www\phpinfo.php on line 2\r\r\n
[12-Jun-2011 13:01:12] PHP Notice:  Undefined variable: test in C:\www\phpinfo.php on line 2\r\r\n
[12-Jun-2011 13:02:11] PHP Notice:  Undefined variable: test in C:\www\phpinfo.php on line 2\r\r\n
[12-Jun-2011 13:11:23] PHP Notice:  Undefined variable: test in C:\www\phpinfo.php on line 2\r\r\n
[12-Jun-2011 13:12:10] PHP Notice:  Undefined variable: test in C:\www\phpinfo.php on line 2\r\r\n

Two carriage return character and one new line per one error line.

Why it happens? How to change error log file to default format:

[12-Jun-2011 12:58:55] PHP Notice:  Undefined variable: test in C:\www\phpinfo.php on line 2\r\n
[12-Jun-2011 12:59:01] PHP Notice:  Undefined variable: test in C:\www\phpinfo.php on line 2\r\n
[12-Jun-2011 13:01:12] PHP Notice:  Undefined variable: test in C:\www\phpinfo.php on line 2\r\n
[12-Jun-2011 13:02:11] PHP Notice:  Undefined variable: test in C:\www\phpinfo.php on line 2\r\n
[12-Jun-2011 13:11:23] PHP Notice:  Undefined variable: test in C:\www\phpinfo.php on line 2\r\n
[12-Jun-2011 13:12:10] PHP Notice:  Undefined variable: test in C:\www\phpinfo.php on line 2\r\n

PHP Version 5.3.6
Apache/2.2.15 (Win32)
Tested on Windows 7 Home Basic and Windows XP SP3, same results.

php.ini file contains only two strings

log_errors = On
error_log = c:/server/php.log

apache phpinfo() script -> http://pastehtml.com/view/awvx1vgpp.html

PS.

sever: nginx 1.0.4
FastCGI + PHP Version 5.3.6

Everything works as expected.
nginx phpinfo() script -> http://pastehtml.com/view/awvwvk9p9.html

Answer

hakre picture hakre · Jun 12, 2011

There are more ini directives to control the output into the error log. These are explained on this PHP manual page.

By default, PHP running with not loading the ini and only having the error_log set and logging enabled, it does output a single line only. You can test that on your system as well, it demonstrates it well for the Command Line Interface (CLI) "Server Application Programming Interface (API) [SAPI]":

php -n -d error_log=./error.log -d log_errors=1 -r 'error;'

Use this command to make an isolated run and compare it with your output. If it has two line endings as well, then this is probably a bug of your php version.

If not a problem with the PHP version [not the case in the original posting (OP)] then within your application some settings looks to be altered. You need to find out which setting. Probably you can find it by registering an own error handler and then dumping the ini settings.

Last but not least, if it isn't a misunderstanding of the line ending (see my comment), then one may want to also look in the ini settings named error_prepend_string and error_append_string regarding the error display (but not the error logging).