Current time: 04-16-2014, 03:29 AM Hello There, Guest! (LoginRegister)

Post Reply 
Allowed memory size of 94371840 bytes exhausted
11-19-2010, 12:16 PM
Post: #1
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?

<b>Fatal error</b>: Allowed memory size of 94371840 bytes exhausted (tried to allocate 63782913 bytes) in <b>/home/ptrmusic/ptrmusic.com/download.php</b> on line <b>79</b><br />

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...

...

$buffer='';

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

...

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

then line 79 is...

echo $buffer;

Thanks in advance...
Find all posts by this user
Quote this message in a reply
11-19-2010, 12:52 PM
Post: #2
RE: Allowed memory size of 94371840 bytes exhausted
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 http://discussion.dreamhost.com/thread-127481.html for details.
Find all posts by this user
Quote this message in a reply
11-19-2010, 01:38 PM
Post: #3
RE: Allowed memory size of 94371840 bytes exhausted
Ok will research. Thanks! Could you resend the link? I'm getting a 404 on that thread.

(11-19-2010 12:52 PM)andrewf Wrote:  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 http://discussion.dreamhost.com/thread-127481.html for details.
Find all posts by this user
Quote this message in a reply
11-19-2010, 02:45 PM
Post: #4
RE: Allowed memory size of 94371840 bytes exhausted
Fixed the link. My bad.
Find all posts by this user
Quote this message in a reply
11-19-2010, 08:54 PM
Post: #5
RE: Allowed memory size of 94371840 bytes exhausted
So I got the apache module X-Sendfile working thanks to AndrewF's help. THANKS very much! :-D

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.

Code:
<?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..
Find all posts by this user
Quote this message in a reply
Post Reply 


Forum Jump: