|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2004-10-11 10:13 UTC] richard dot quadling at bandvulc dot co dot uk
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]
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sun Oct 26 02:00:01 2025 UTC |
NOT IIS!!!!!! I'm using Sambar Server with ISAPI and CLI. If the error log file is now being opened in binary mode, then the line endings are wrong somehow. <?php $a = 1 / 0; ?> generates different line endings when run via a browser and when run via the CLI. [25-Nov-2005 12:03:57] PHP Warning: Division by zero in Unknown on line 0 [25-Nov-2005 12:03:58] PHP Warning: Division by zero in Unknown on line 0 [25-Nov-2005 12:03:59] PHP Warning: Division by zero in Unknown on line 0 [25-Nov-2005 12:03:59] PHP Warning: Division by zero in Unknown on line 0 [25-Nov-2005 12:03:59] PHP Warning: Division by zero in Unknown on line 0 [25-Nov-2005 12:03:59] PHP Warning: Division by zero in Unknown on line 0 [25-Nov-2005 12:03:59] PHP Warning: Division by zero in Unknown on line 0 [25-Nov-2005 12:04:00] PHP Warning: Division by zero in Unknown on line 0 [25-Nov-2005 12:04:00] PHP Warning: Division by zero in Unknown on line 0 [25-Nov-2005 12:04:00] PHP Warning: Division by zero in Unknown on line 0 [25-Nov-2005 12:05:13] PHP Warning: Division by zero in Unknown on line 0 [25-Nov-2005 12:05:14] PHP Warning: Division by zero in Unknown on line 0 [25-Nov-2005 12:05:15] PHP Warning: Division by zero in Unknown on line 0 [25-Nov-2005 12:05:15] PHP Warning: Division by zero in Unknown on line 0 [25-Nov-2005 12:05:15] PHP Warning: Division by zero in Unknown on line 0 [25-Nov-2005 12:05:15] PHP Warning: Division by zero in Unknown on line 0 [25-Nov-2005 12:05:15] PHP Warning: Division by zero in Unknown on line 0 [25-Nov-2005 12:05:15] PHP Warning: Division by zero in Unknown on line 0 Additional \r when ran from ISAPI. Here is the thing. In windows, fopen("file","a") will open a file in TEXT mode. This means ANY \n will become \r\n when the file is written. This is the nature of the C library. All known and correct. So, if the line ending as defined in main\php.h says that lines endings are \r\n AND the file is opened in text mode (which it was), then \r\n will become \r\r\n which is does. BUT only for the ISAPI version. Now. I've amended the script to show DIRECTORY_SEPARATOR and PHP_EOL ... <?php var_dump(DIRECTORY_SEPARATOR); var_dump(PHP_EOL); $a = 1 / 0; ?> On both ISAPI and CLI, the output on screen is the same. The PHP_EOL is 2 bytes in size. This is correct. But when that gets to the error log file, it is wrong. An extra \r has crept in somewhere. This is on PHP 5.0.5. I'm just about to try out 5.1.0