Forum Moderators: coopster

Message Too Old, No Replies

fread problems, cant retrieve bigger than 30mb

         

brandon0401

7:38 pm on Nov 14, 2007 (gmt 0)

10+ Year Member



Hey guys, using a simple download script to retrieve a media file from a url. It works, but it seems to stop working around 32 mb. Why is this? I believe my timeout settings are high enough. Thanks.

here is a quick snippit...code started in browser, but ive tried to dull it down and run in shell to help debug and not worry about header issues...

function download ($file_source, $file_target)
{
// Preparations
$file_source = str_replace(' ', '%20', html_entity_decode($file_source)); // fix url format
if (file_exists($file_target)) { chmod($file_target, 0777); } // add write permission

// Begin transfer
if (($rh = fopen($file_source, 'rb')) === FALSE) { return false; } // fopen() handles
if (($wh = fopen($file_target, 'wb')) === FALSE) { return false; } // error messages.
$test = 0;
$filesize = filesize($rh);
echo($filesize);
echo($file_source);
while (!feof($rh))
{
$test = $test + 1024;

fread($rh, 1024);
}
*THE FILE FROM THE ABOVE ALWAYS STOPS AROUND 30 mb or so, but in bytes obvioulsy...***writing seems fine
echo($test);
fwrite($wh, $rh);
echo("after");
fclose($rh);
fclose($wh);
return true;
}
print "asdfasdf";
$videourl = "http://www.example.com/whatever.mpg";
echo $videourl;
$randname = rand(1000000, 9999999);
$ext2 = substr(strrchr($videourl, '.'), 1);
//$ext2 = substr(strrchr($videourl, '.'));
$randname .= ".".$ext2;
$temp_dir = "/home/user/www/whatever.mpg";
download($videourl, $temp_dir);

****
THis is how I had read/write combined in above code before I seperated and isolated to the read just fyi
while (!feof($rh))
{
if (fwrite($wh, fread($rh, 1024)) === FALSE) { fclose($rh); fclose($wh); return false; }
}

****

*left the echos in so you can see the data points

thanks!

eelixduppy

6:52 pm on Nov 19, 2007 (gmt 0)



>>but it seems to stop working

It seems to be a memory issue. Are you getting any error messages?

Menekali

10:27 pm on Nov 19, 2007 (gmt 0)

10+ Year Member



This may help?

[webmasterworld.com...]

brotherhood of LAN

1:26 am on Nov 30, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



also consider that some shared hosts put a limit on the amount of memory your scripts/site can consume.

You didn't mention what machine you're running the script from so it's worth a mention.