php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #37481 "Memory exhausted" errors cause internal server error rather than E_ERROR
Submitted: 2006-05-17 18:34 UTC Modified: 2006-08-03 20:45 UTC
From: phpbugs at thequod dot de Assigned: dmitry
Status: Closed Package: CGI/CLI related
PHP Version: 5CVS-2006-05-17 (CVS) OS: Ubuntu Linux
Private report: No CVE-ID:
 [2006-05-17 18:34 UTC] phpbugs at thequod dot de
Description:
------------
If memory_limit gets reached, I get "Allowed memory size 
of XXX bytes exhausted (tried to allocate XXX bytes)" 
written to the server's main error log and 

[Wed May 17 20:22:26 2006] [error] [client XXX] 
(104)Connection reset by peer: FastCGI: comm with 
server "/var/www/XXX/php5-fcgi-starter" aborted: read 
failed
[Wed May 17 20:22:26 2006] [error] [client XXX] FastCGI: 
incomplete headers (0 bytes) received from 
server "/var/www/XXX/php5-fcgi-starter"

into the virtual host's error log.

Reproduce code:
---------------
<?php
ini_set('memory_limit', '1M' );

$s = '';
while( 1 )
        $s .= 'foo';
?>


Expected result:
----------------
[Wed May 17 20:23:49 2006] [error] [client XXX] FastCGI: 
server "/var/www/XXX/php5-fcgi-starter" stderr: PHP Fatal 
error: Allowed memory size of XXX bytes exhausted (tried 
to allocate XXX bytes) in /var/www/XXX/web/index.php on 
line XXX


Actual result:
--------------
No entry about the exhausted memory in the virtual host's 
error log, but only in the main error log, _without_ any 
source file or line mentioned (which is the case with 
mod_php AFAIK)

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2006-05-17 18:48 UTC] tony2001@php.net
This is the way it works and this is expected.
 [2006-05-17 19:00 UTC] phpbugs at thequod dot de
I don't see why.

Additionally, as far as I remember, the behaviour is 
different with mod_php: the error gets displayed in the 
browser (with display_errors "on") and therefor probably 
also get logged into the virtual host's error log.

IMHO it's very confusing to just have the error, without 
any time, file or vhost information in the main error.log!
 [2006-05-17 19:45 UTC] tony2001@php.net
PHP has nothing to do with your web server logging utilities.
 [2006-05-17 20:12 UTC] phpbugs at thequod dot de
Apache does not attach the "in FILE on LINE" to the error 
PHP creates!

Re: "mod_fastcgi logs FastCGI application error (stderr) 
output to the server log associated with the request. 
Errors reported by the FastCGI process manager, fcgi-pm, 
are reported to the main server log (typically, 
logs/error_log). Data written to stdout or stderr before 
entering the FastCGI accept loop or via a mechanism that 
is not FastCGI protocol aware will also be directed to the 
main server log." 
(http://www.fastcgi.com/mod_fastcgi/docs/mod_fastcgi.html)
it seems that the "memory exhausted" error is "Data 
written to stdout or stderr before entering the FastCGI 
accept loop or via a mechanism that is not FastCGI 
protocol aware".

I also don't see any reason why mod_php would 
display/deliver the page that has been processed/created 
before this error, but the php-fastcgi returns an invalid 
response.
 [2006-05-24 11:06 UTC] dmitry@php.net
Probably this is configuration problem. Try the following directives in your php.ini

log_errors=E_ALL
report_zend_debug=0

They may satisfy your expectation (work for me).

I cannot reproduce server interanl error and "Connection reset by peer" and "incomplete headers" messages. Please confirm that you still have the problem or close the bug.

 [2006-05-24 17:21 UTC] phpbugs at thequod dot de
I have
log_errors=On (rather than E_ALL)
error_reporting=E_ALL
and
error_log not set.

IF I set error_log to some file, the fatal error gets 
logged there:
[24-May-2006 19:11:49] PHP Fatal error:  Allowed memory 
size of 1048576 bytes exhausted (tried to allocate 6 
bytes) in /XXX/web/test/memory.php on line 10

In the Apache main error.log I then get:
Allowed memory size of 1048576 bytes exhausted (tried to 
allocate 44 bytes)
[Wed May 24 19:14:24 2006] [warn] FastCGI: 
server "/XXX/fcgi-scripts/XXX/php5-fcgi-starter" (pid 
2637) terminated by calling exit with status '1'
[Wed May 24 19:14:24 2006] [warn] FastCGI: 
server "/XXX/fcgi-scripts/XXX/php5-fcgi-starter" (uid 
1001, gid 1001) restarted (pid 2767)

and in the VHOST's error log:
[Wed May 24 19:14:24 2006] [error] [client X] 
(104)Connection reset by peer: FastCGI: comm with 
server "/XXX/fcgi-scripts/XXX/php5-fcgi-starter" aborted: 
read failed
[Wed May 24 19:14:24 2006] [error] [client X] FastCGI: 
incomplete headers (0 bytes) received from 
server "/XXX/fcgi-scripts/XXX/php5-fcgi-starter"

IMHO, with error_log set it's even more bad: the 
fcgi-starter script exits, although I'm using 
PHP_FCGI_CHILDREN=4!

report_zend_debug does not seem to make a difference, and 
is "On" by default (not in my php.ini?!)

I've just tested it with current CVS PHP_5_1.
 [2006-07-19 14:29 UTC] dmitry@php.net
Could you retest it with current PHP_5_2. New memory manager may fix this problem.
 [2006-07-19 22:11 UTC] phpbugs at thequod dot de
It works!

Though it's now a bit too verbose (reference to source 
code/zend_operators).


VirtualHost log:

[Thu Jul 20 00:00:04 2006] [error] [client X] FastCGI: 
server "/X/php5-fcgi-starter" stderr: PHP Fatal error:  
Allowed memory size of 1048576 bytes exhausted 
at /X/cvs/php/PHP_5_2/Zend/zend_operators.c:1183 (tried to 
allocate 786358 bytes) in /X/public_html/bug_37481.php on 
line 6


Main server error log:
/X/public_html/bug_37481.php(6) : Fatal error - Allowed 
memory size of 1048576 bytes exhausted 
at /X/cvs/php/PHP_5_2/Zend/zend_operators.c:1183 (tried to 
allocate 786358 bytes)
 [2006-07-20 06:29 UTC] tony2001@php.net
Fixed -> closed.
 [2006-07-20 11:06 UTC] phpbugs at thequod dot de
Should I open another bug because the (now working) error message is too verbose??
 [2006-08-03 20:36 UTC] phpbugs at thequod dot de
Re-opened, because it's too verbose - there should be no 
reference to Zend/zend_operators.c:1183.

Just re-tested with PHP_5_2
 [2006-08-03 20:45 UTC] tony2001@php.net
The error message is the same everywhere and it includes some debug information required to understand where exactly the memory was exhausted.
We're not going to change it just because you consider it too verbose.
 
PHP Copyright © 2001-2014 The PHP Group
All rights reserved.
Last updated: Fri Apr 18 13:02:15 2014 UTC