php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #42389 PHP+Apache2+mod_fcgid kills all processes after submit
Submitted: 2007-08-22 20:39 UTC Modified: 2007-09-03 14:00 UTC
From: webmaster at machostlink dot net Assigned:
Status: Closed Package: CGI/CLI related
PHP Version: 5.2CVS-2007-08-23 OS: OSX 10.4.10
Private report: No CVE-ID: None
 [2007-08-22 20:39 UTC] webmaster at machostlink dot net
Description:
------------
When using a simple upload form to submit a file, all php4-cgi & php5-cgi processes (parent & children) are killed and server throws "500 Internal Server Error" message. This happens ONLY when filesize is larger then 4KB.

Apache error.log from vhost
---------------------------
[warn] (35)Resource temporarily unavailable: mod_fcgid: write data to fastcgi server error

Apache error.log from main/default server
-----------------------------------------
mod_fcgid: process /Volumes/home/www/vhost1/public_html/test.php(2293) exit(communication error), terminated by calling exit(), return code: 0

I am not sure now, after reading other (older) bug reports  regarding   cgi problems, if this is not an older issue as well!? However, since I could not find many similarities to these posts I decided to file this one.

I am running PHP 4.4.7 & PHP 5.2.3 as CGI using mod_fcgid 2.2 and Apache 2.2.4



Reproduce code:
---------------
<?php
$uploaddir = '/tmp/';
$uploadfile = $uploaddir . basename($_FILES['userfile']['name']);

echo '<pre>';
if (move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadfile)) {
    echo "File is valid, and was successfully uploaded.\n";
} else {
    echo "Possible file upload attack!\n";
}

echo 'Here is some more debugging info:';
print_r($_FILES);

print "</pre>";

?>
<form enctype="multipart/form-data" action="<?=$_SERVER['PHP_SELF']?>" method="POST">
    <input type="hidden" name="MAX_FILE_SIZE" value="30000" />
    Send this file: <input name="userfile" type="file" />
    <input type="submit" value="Send File" />
</form>

Expected result:
----------------
File is valid, and was successfully uploaded.
Here is some more debugging info:Array
(
    [userfile] => Array
        (
            [name] => test.jpg
            [type] => image/jpeg
            [tmp_name] => /Volumes/home/www/vhost1/tmp/phpcYOdvd
            [error] => 0
            [size] => 24852930
        )

)

Actual result:
--------------
Error 500
Internal Server Error
...

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2007-08-23 09:06 UTC] jani@php.net
Please try using this CVS snapshot:

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

For Windows (installer):

  http://snaps.php.net/win32/php5.2-win32-installer-latest.msi

I can't reproduce anything like this, even when uploading quite large files so try the snapshot first. (any possibility that this isn't any PHP bug at all..? :)
 [2007-08-23 09:13 UTC] webmaster at lifedit dot com
Right, I was taken that already in consideration and posted a report on "mod_fcgid users bug tracker" as well. But looking at the history of somewhat related php-cgi problems and bug reported I think it is more likely to be a PHP bug.

My problem is that I have a hosting service and I rely on both PHP5 & PHP4 because I do have clients who still have PHP4 applications they want to run. So even if it does work with the latest CVS (which I will try out) I still have a need for this feature to run on PHP4 as well. :(
 [2007-08-23 11:41 UTC] webmaster at machostlink dot net
Ok, I checked the latest CVS snapshot but the problem still remains the same.

I forgot to mention in my inital post that I am using Apache2 with mod_suexec for permissions. But that seems to work fine according to suexec.log and apache2 error.log files. Thought I mention it now anyway just in case.
 [2007-08-23 12:01 UTC] jani@php.net
Regarding any PHP 4 fixes, see php.net for latest NEWS: "PHP 4 end of life announcement"

This isn't any critical issue so it's very unlikely it will get fixed in PHP 4 (even if there were any more releases of PHP 4..)

And I still think this isn't PHP bug. Do you know if PHP is outputting any errors? Do you have logging enabled? Are you sure you haven't hit any limits set in php.ini for max size for uploaded file for example..?
 [2007-08-23 12:25 UTC] webmaster at machostlink dot net
Yeah I saw the news "PHP 4 end of life announcement" and I know that bug reports for it probably won't be fixed unless they are critical issues. I find it funny that both PHP versions are behaving like that...

I checked the PHP config for this vhost again and again and tried different settings:

Right now I have:
------------------
max_execution_time = 60
max_input_time = 120
memory_limit = 64M
error_reporting  =  E_ALL & ~E_NOTICE
display_errors = On
log_errors = On
log_errors_max_len = 1024

But even after some testing now, still no PHP error.log to be seen!?
 [2007-08-23 14:13 UTC] jani@php.net
You forgot to set 'error_log = /path/to/php_error.log' 
 [2007-08-23 15:35 UTC] webmaster at machostlink dot net
Sorry I forgot to add that.. I had a path set but only the path not the  filename. Well so this time PHP did create a log but nothing in it when the "500 Internal Error" occurs. Well how should it write into the log when all the processes are killed at once!?
 [2007-08-23 22:23 UTC] jani@php.net
Good point. :)
 [2007-08-23 22:25 UTC] jani@php.net
My guess is it's crashing so you should try and attach GDB to the running process and see what the crash is about (note: you need to use latest CVS snapshot configured using --enable-debug option!)

Make sure you only start 1 PHP FastCGI child, check what it's pid is and attach gdb:

# gdb /path/to/php-cgi <pid>

 [2007-08-24 02:52 UTC] crrodriguez at suse dot de
what is the value of MaxRequestsPerProcess in your mod_fcgid configuration, it should be -1 

This is a known issue of mod_fcgid see the documentation

http://fastcgi.coremail.cn/doc.htm

This is not a bug in PHP.
 [2007-08-24 02:54 UTC] crrodriguez at suse dot de
err.. I meant it should be set to 500 NOT -1
 [2007-08-24 04:47 UTC] webmaster at machostlink dot net
@jani

Ok will do and let you know what the result is.

@crrodriguez

Here is my config for mod_fcgid:
----------------------------------
<IfModule fcgid_module>
SharememPath /tmp/fcgid_shm
SocketPath /opt/local/apache2/logs/fcgidsock
IPCConnectTimeout 60
IPCCommTimeout 60
MaxRequestsPerProcess 500
MaxRequestInMem 1500000
MaxRequestLen 1500000
</IfModule>

I think I have tried EVERY possible combination there is. I read ALL the threads and issues posted on sourceforge page as well as pretty much every thread I could find on google regarding mod_fcgid issues. :( That's why I am quite desperate to solve this.

Thanks for you help...
 [2007-08-24 15:16 UTC] webmaster at machostlink dot net
Ok, now here is the output for latest CVS:

Attaching to program: `/usr/local/bin/php-cgi', process 25912.
Reading symbols for shared libraries .. done
0x9004eb97 in accept ()
(gdb) c
Continuing.

Program received signal SIGPIPE, Broken pipe.
0x9001029c in write ()
(gdb) bt
#0  0x9001029c in write ()
#1  0x002e79b3 in fcgi_flush (req=0xbfffdc00, close=1) at /usr/local/php5.2-200708230830/sapi/cgi/fastcgi.c:543
#2  0x002e7a29 in fcgi_finish_request (req=0xbfffdc00) at /usr/local/php5.2-200708230830/sapi/cgi/fastcgi.c:1163
#3  0x002e825f in fcgi_accept_request (req=0xbfffdc00) at /usr/local/php5.2-200708230830/sapi/cgi/fastcgi.c:869
#4  0x002ea880 in main (argc=1, argv=0xbffffdd0) at /usr/local/php5.2-200708230830/sapi/cgi/cgi_main.c:1491
 [2007-08-30 19:03 UTC] webmaster at machostlink dot net
Any news on this?
 [2007-09-03 10:53 UTC] jani@php.net
Check for these setting in the phpinfo() output for the failing vhost:

post_max_size = 8M
upload_max_filesize = 2M

 [2007-09-03 12:46 UTC] webmaster at machostlink dot net
Is set to:

post_max_size = 8M
upload_max_filesize = 6M

However, I have some good news but not sure if that still does not effect PHP as well anyway. I now tried to run this completely WITHOUT mod_fcgid/mod_fastcgi just as plain and simple CGI. And it does work then without ANY flaws. I guess that means PHP CGI is alright and it's all because of mod_fcgid? Or is PHP executed any different when running thru mod_fcgid/mod_fastcgi?
 [2007-09-03 14:00 UTC] jani@php.net
It is different. But I can't reproduce it using lighttpd so I'd say it's not PHP bug at all. I suggest you ditch Apache and move to the lighttpd camp. :) 

If you can reproduce this with lighttpd, reopen.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Mar 29 14:01:28 2024 UTC