You are here: Re: [PHP] how to stream a movie file with fread « PHP « IT news, forums, messages
Re: [PHP] how to stream a movie file with fread

Posted by Philip Hallstrom on 10/03/68 11:27

> I am trying to stream a movie file with 'fread'
> this my first step in trying to dynamically encrypt the file as it is being
> streamed from the server
>
> do I need to fread the data in chunks?
> If so, how?
>
> $filename ="$path2file";
> $file = fopen($filename,'r');
> $fileSize = filesize($filename);
> $ContentType = " video/quicktime";
> header ("Content-type: $ContentType");
> header ("Content-length: $fileSize");
>
> while( $filedata_temp = fread($file, $fileSize) )
> echo $filedata_temp;
>
> <b>Fatal error</b>: Allowed memory size of 16777216 bytes exhausted (tried
> to allocate 24113191 bytes) in <b>xxxxxxxx/fopenTest.php</b> on line
> <b>27</b><br />

Not knowing exactly what you're trying to accomplish...

I'm guessing that your $filename file is 24113191 in size and that PHP is
compiled with a memory limit of 16777216. And since your assigning the
results of fread() to a variable, PHP is going to try an allocate that for
you and is failing.

Couple of points..

Why loop if you are reading the entire file at once? Which is what
fread($file, $fileSize) is going to do?

Instead perhaps you want this:

while ( !feof($file) ) {
echo fread($file, 32768);
}

(or some other value for 32768...)

That keeps the memory usage down, but does the same thing...

good luck!

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация