Serving a large file through PHP without hitting memory_limit

Trackback - September 10, 2008

Ran into a little problem hitting the memory limit for PHP when serving 100MB+ files through a script like:

$file = @fopen($filename,"r");<br/><br />
if ($file)<br />
{<br />
while(!feof($file))<br />
{<br />
    print(fread($file, 1024*4));<br />
    flush();<br />
    ob_flush();<br />
}<br />
@fclose($file);<br />
}

Found that you need to call ob_flush() as well as flush() since flush() has no effect on the buffering scheme of your web server.

Just thought I’d throw that out there for anyone else.

Tags: , ,

Comments


No comments yet.

Leave a comment

(required)

(required)