Allowed memory size of 94371840 bytes exhausted

Hey All,

I’m getting this error in my code. Was wondering if someone could shed some light?

Fatal error: Allowed memory size of 94371840 bytes exhausted (tried to allocate 63782913 bytes) in /home/ptrmusic/ on line 79

We offer mp3s to our customers. Most file sizes are under 25 meg and our download.php works fine. This one in particular is 60 meg. Under the 90 meg limit specified in our phpinfo.php. Curious to know why it’s not working.

Here is a bit of the code…


if ( $fp )
while (!feof($fp))
$buffer .= fgets($fp, 4096);

header(‘Content-Type: application/mp3’);
header(‘Content-Disposition: attachment; filename=’.$file_name.’.mp3’);

then line 79 is…

echo $buffer;

Thanks in advance…

Due to the way PHP allocates memory internally, that script will use considerably more than 60 MB while it’s running (it may end up using as much as 120 MB at times).

mod_xsendfile is a much better approach for this type of script overall. See for details.

Ok will research. Thanks! Could you resend the link? I’m getting a 404 on that thread.

Fixed the link. My bad.

So I got the apache module X-Sendfile working thanks to AndrewF’s help. THANKS very much! :smiley:

I’m going to use this as an alternative to my fgets() method.

I found some code at this site and will share it here to get you going if your lost.

<?php //We want to force a download box with the filename hello.txt header('Content-Disposition: attachment;filename=hello.txt'); //File is located at /home/username/hello.txt header('X-Sendfile: /home/username/hello.txt'); ?>
If you need to know more about XSendfile check this…