httpd-bugs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bugzi...@apache.org
Subject DO NOT REPLY [Bug 30005] New: - Apache stores all PHP produced content in memory plus possible leaked memory
Date Fri, 09 Jul 2004 15:53:08 GMT
DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG 
RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT
<http://issues.apache.org/bugzilla/show_bug.cgi?id=30005>.
ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND 
INSERTED IN THE BUG DATABASE.

http://issues.apache.org/bugzilla/show_bug.cgi?id=30005

Apache stores all PHP produced content in memory plus possible leaked memory

           Summary: Apache stores all PHP produced content in memory plus
                    possible leaked memory
           Product: Apache httpd-2.0
           Version: 2.0.49
          Platform: PC
        OS/Version: Linux
            Status: NEW
          Severity: Normal
          Priority: Other
         Component: Core
        AssignedTo: bugs@httpd.apache.org
        ReportedBy: jukkaho@mail.student.oulu.fi


System:
Linux suihkari 2.6.6-rc2 #2 SMP Thu May 6 12:33:19 EEST 2004 i686
PHP Version 4.3.7 with Alternative PHP Cache module
Apache/2.0.49 (Gentoo/Linux) mod_ssl/2.0.49 OpenSSL/0.9.7d PHP/4.3.7

Problem is that Apache appears to cache all content in memory when content is
generated in PHP script. This makes it impossible to send very large files
through PHP scripts with decent performance as server tries to keep hundreds of
megabytes or more in memory.

I guess that the cause of this problem is generic Range-header support through
Byterange filter or something similar that does not care that all necessary
headers (HTTP/1.1 206 Partial Content, Content-Size, Accept-Range,
Content-Location, Content-Range) have all been set already. Only reason to cache
content (that I can think of) is to get some header lines (like Content-Size and
Content-Range) to have correct values. However, this is currently happening for
all cases (resuming, non-resuming) which I concider to be a bug.

I also think that If I send all the relevant headers myself already, Apache
shouldn't need to touch the content any more (and therefore cache it) and
performance gain should be significant, because everything could be just passed
through.

Also, memory usage seems to stay high (like leaked memory) even when client has
already received full file and closed connection. Next request will further
increase memory usage.

Stopping apache service and downloading a single 91 MB file through PHP causes
Apache process size to grow about 91 MB:

  PID USER      PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+  COMMAND
 2708 apache    15   0  138m  95m  48m S  0.0 19.0   0:01.95 apache2

This problem is NOT reproducible with Apache 1.3.29 and PHP 4.3.3. This could
also be a PHP problem when interfacing Apache2, but I don't have any proof or
even reason to assume that.

Following simple PHP script should demonstrate memory usage for non-resumable
case, where resuming is actually expected to need more memory for header
calculations and where memory usage stays high afterwards:

<?php
 // Just change the filename for something existing and large
 $filename="something-large.tar.gz";
                                                                               
                                                                               
                                    
 header("Content-Length: $size");
 header("Content-type: application/octet-stream");
                                                                               
                                                                               
                                    
 $size=filesize($filename); // false if failed, but I don't check for errors now
                                                                               
                                                                               
                                    
 // Send file.

 if (!($fp=@fopen($filename,"r")))
 {
  header("HTTP/1.1 404 Not Found");
  header("Content-type: text/plain");
  echo "Not found.";
  exit;
 }

 while (!feof($fp))
 {
  $buf=fread($fp,4096);
  echo $buf; // This line is needed for memory leak to happen
 }

 @fclose($fp);
?>

---------------------------------------------------------------------
To unsubscribe, e-mail: bugs-unsubscribe@httpd.apache.org
For additional commands, e-mail: bugs-help@httpd.apache.org


Mime
View raw message