php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #30393 CLI and ISAPI give different line endings in ERRORS.LOG file.
Submitted: 2004-10-11 10:13 UTC Modified: 2005-11-25 14:48 UTC
Votes:3
Avg. Score:3.0 ± 1.6
Reproduced:3 of 3 (100.0%)
Same Version:1 (33.3%)
Same OS:2 (66.7%)
From: richard dot quadling at bandvulc dot co dot uk Assigned:
Status: Closed Package: *Web Server problem
PHP Version: 5.0.2 OS: Windows XP SP2
Private report: No CVE-ID: None
 [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]

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2004-10-11 10:38 UTC] richard dot quadling at bandvulc dot co dot uk
I may have got the CLI / ISAPI bits back to front half way through this.

Sorry.
 [2005-03-07 22:04 UTC] sniper@php.net
Please try using this CVS snapshot:

  http://snaps.php.net/php5-latest.tar.gz
 
For Windows:
 
  http://snaps.php.net/win32/php5-win32-latest.zip


 [2005-03-15 01:00 UTC] php-bugs at lists dot php dot net
No feedback was provided for this bug for over a week, so it is
being suspended automatically. If you are able to provide the
information that was originally requested, please do so and change
the status of the bug back to "Open".
 [2005-11-25 12:49 UTC] richard dot quadling at bandvulc dot co dot uk
Still not working.

Errors logged from CLI and ISAPI have different line endings on Windows.
 [2005-11-25 13:03 UTC] tony2001@php.net
>The function php_log_err (main\main.c line 344) only uses
> append mode - "a" - to open the file.
No, it doesn't:
log_file = VCWD_FOPEN(PG(error_log), "ab");

>Which will be in text mode and "\r\n" will
>become "\r\r\n", as "\n" => "\r\n" in a text file.
Could you plz explain this?
Why "\n" will suddenly become "\r\n" ?
 [2005-11-25 13:22 UTC] richard dot quadling at bandvulc dot co dot uk
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
 [2005-11-25 13:24 UTC] richard dot quadling at bandvulc dot co dot uk
The main.c line I'm interested in was changed 3 months ago ...

http://cvs.php.net/co.php/php-src/main/main.c?r=1.645

 Revision 1.645, Wed Aug 17 03:52:17 2005 (3 months, 1 week ago) by sniper
Changed since 1.644: +2 -2
Log:
Fix EOLs under winblows

 log_file = VCWD_FOPEN(PG(error_log), "ab");

Prior to this it was just "a"
 [2005-11-25 13:28 UTC] tony2001@php.net
Reopen when you try 5.1 for real.
 [2005-11-25 14:48 UTC] richard dot quadling at bandvulc dot co dot uk
ARGH!

Why do I work with monkeys. Hmmm. Nice mirror!

Sorry.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Mar 19 11:01:28 2024 UTC