From: richard dot quadling at bandvulc dot co dot uk
Operating system: Windows XP SP2
PHP version: 5.0.2
PHP Bug Type: Scripting Engine problem
Bug description: CLI and ISAPI give different line endings in ERRORS.LOG file.
Description:
------------
I use both CLI and ISAPI PHP code.
I have PHP.INI set to log errors to "PHP Errors.log".
If I have an error in a CLI program, the error that is logged ends with
CR/LF.
If I have an error in a ISAPI program (i.e. launched by a web server), I
get the error with CR/CR/LF. One too many CR.
An example from my error log file (hoping that this gets through
cleanly)...
[08-Oct-2004 15:00:03] PHP Notice: Undefined offset: 1 in C:\McAfee
AntiVirus Updates\AVUpdate.php on line 90[cr/lf]
[08-Oct-2004 15:00:03] PHP Notice: Undefined offset: 2 in C:\McAfee
AntiVirus Updates\AVUpdate.php on line 90[cr/lf]
[08-Oct-2004 15:18:54] PHP Notice: Undefined variable: _SESSION in
C:\WebSites\PHP\Includes\class_Form_Maint.inc on line 332[cr/cr/lf]
[08-Oct-2004 15:18:54] PHP Notice: Undefined variable: sRequireFormAction
in C:\WebSites\PHP\Includes\class_Form_Maint.inc on line 332[cr/cr/lf]
[08-Oct-2004 15:18:54] PHP Notice: Undefined variable: _SESSION in
C:\WebSites\PHP\Includes\class_Form_Maint.inc on line 332[cr/cr/lf]
I'm not using the CGI version.
Having examined the source, I can see why this happens the extra CR
occurs.
In Windows, opening a file using C's fopen, will open the file in text
mode unless 'b' as a mode.
So, the constant PHP_EOL is set to "\r\n" (main\php.h line 58).
The function php_log_err (main\main.c line 344) only uses append mode -
"a" - to open the file. Which will be in text mode and "\r\n" will become
"\r\r\n", as "\n" => "\r\n" in a text file.
But, why this is not true for the CLI version ...
Now. The PHP_EOL was added by 5.0.2 (NEWS line 10).
Examining main\php.h (Lines 49 to 68) it LOOKS like there is a way through
to setting PHP_EOL to \n (which is what the CLI version is outputting.
I am not sure, but is the constant PHP_WIN32 set for ALL windows forms of
PHP (ISAPI, CGI, CLI)? If not, then this may be a cause. I can see no
other way that PHP_EOL could NOT be "\r\n" (which is wrong for a text
file, but ...).
Solution? I think opening the error file in binary mode ("ab") will mean
you do not need to change the PHP_EOL.
As a final request, is there any one who can help me get PHP to compile? I
don't have newsgroup access here.
Regards,
Richard Quadling.
Reproduce code:
---------------
Set PHP ...
error_log = C:\WebSites\PHP\PHP Errors.log
and then any PHP code that will generate an error.
<?php
$var = 1 / 0; // Cannot divide by zero.
?>
Run this in both CLI and ISAPI mode.
I ran the program 4 times, first in ISAPI mode (via a webpage) and then in
CLI mode.
Expected result:
----------------
[11-Oct-2004 09:09:22] PHP Warning: Division by zero in Unknown on line
0[cr/lf]
[11-Oct-2004 09:09:36] PHP Warning: Division by zero in Unknown on line
0[cr/lf]
[11-Oct-2004 09:09:37] PHP Warning: Division by zero in Unknown on line
0[cr/lf]
[11-Oct-2004 09:09:37] PHP Warning: Division by zero in Unknown on line
0[cr/lf]
[11-Oct-2004 09:09:56] PHP Warning: Division by zero in Unknown on line
0[cr/lf]
[11-Oct-2004 09:09:57] PHP Warning: Division by zero in Unknown on line
0[cr/lf]
[11-Oct-2004 09:09:57] PHP Warning: Division by zero in Unknown on line
0[cr/lf]
[11-Oct-2004 09:09:57] PHP Warning: Division by zero in Unknown on line
0[cr/lf]
Actual result:
--------------
[11-Oct-2004 09:09:22] PHP Warning: Division by zero in Unknown on line
0[cr/cr/lf]
[11-Oct-2004 09:09:36] PHP Warning: Division by zero in Unknown on line
0[cr/cr/lf]
[11-Oct-2004 09:09:37] PHP Warning: Division by zero in Unknown on line
0[cr/cr/lf]
[11-Oct-2004 09:09:37] PHP Warning: Division by zero in Unknown on line
0[cr/cr/lf]
[11-Oct-2004 09:09:56] PHP Warning: Division by zero in Unknown on line
0[cr/lf]
[11-Oct-2004 09:09:57] PHP Warning: Division by zero in Unknown on line
0[cr/lf]
[11-Oct-2004 09:09:57] PHP Warning: Division by zero in Unknown on line
0[cr/lf]
[11-Oct-2004 09:09:57] PHP Warning: Division by zero in Unknown on line
0[cr/lf]
--
Edit bug report at http://bugs.php.net/?id=30393&edit=1
--
Try a CVS snapshot (php4): http://bugs.php.net/fix.php?id=30393&r=trysnapshot4
Try a CVS snapshot (php5.0): http://bugs.php.net/fix.php?id=30393&r=trysnapshot50
Try a CVS snapshot (php5.1): http://bugs.php.net/fix.php?id=30393&r=trysnapshot51
Fixed in CVS: http://bugs.php.net/fix.php?id=30393&r=fixedcvs
Fixed in release: http://bugs.php.net/fix.php?id=30393&r=alreadyfixed
Need backtrace: http://bugs.php.net/fix.php?id=30393&r=needtrace
Need Reproduce Script: http://bugs.php.net/fix.php?id=30393&r=needscript
Try newer version: http://bugs.php.net/fix.php?id=30393&r=oldversion
Not developer issue: http://bugs.php.net/fix.php?id=30393&r=support
Expected behavior: http://bugs.php.net/fix.php?id=30393&r=notwrong
Not enough info: http://bugs.php.net/fix.php?id=30393&r=notenoughinfo
Submitted twice: http://bugs.php.net/fix.php?id=30393&r=submittedtwice
register_globals: http://bugs.php.net/fix.php?id=30393&r=globals
PHP 3 support discontinued: http://bugs.php.net/fix.php?id=30393&r=php3
Daylight Savings: http://bugs.php.net/fix.php?id=30393&r=dst
IIS Stability: http://bugs.php.net/fix.php?id=30393&r=isapi
Install GNU Sed: http://bugs.php.net/fix.php?id=30393&r=gnused
Floating point limitations: http://bugs.php.net/fix.php?id=30393&r=float
MySQL Configuration Error: http://bugs.php.net/fix.php?id=30393&r=mysqlcfg