ob_flush() possible memory leak in Apache

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 




Server Specs
------------
CentOS 4.4
Apache 2.0.52 (httpd-2.0.52-28.ent.centos4)
PHP 5.1.6 (php-5.1.6-1.2.centos)
PHP running as Apache Module.

Simple script reads a file in (mp3 or other binary file) and spits out
to browser. Upon completion, memory consumption of the Apache child
rises dramatically and CPU usage spikes. Same is true under PHP 5.2.0.
Removing ob_flush and using ini_set("output_buffering = Off");
eliminates the problem, but causes others (browser doesn't appear to see
the headers).

Just want to make sure I'm using the function correctly before filing a
bug report. Offending code example below, just add mp3 file. Use 'top -u
apache' to monitor httpd process, RSS (memory) will jump at the end of download. You can safely kill that child process ID without having to restart the entire server.

Chris

<?php
$filename = "test.mp3";
   if ($handle = fopen($filename,"r")) {
       header("Content-Type: application/octet-stream");
       header("Pragma: public");
       header("Expires: 0");
       header("Cache-Control: public, must-revalidate, post-check=0, " .
         "pre-check=0");
       header("Content-Description: File Transfer");
       header("Content-Disposition: attachment; filename=" . $filename);
       header("Content-Transfer-Encoding: binary");
       header("Content-Length: " . filesize($filename));
       while (($content = fread($handle,1024)) !== FALSE) {
         echo $content;
         ob_flush();
         flush();
       }
     }
     fclose($handle);
?>

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux