Hi guys,
I am currently using the following PHP function to stream files:
Code:
/**
* @return void
*/
protected final function stream( $filePath, $offset, $maxLength=null )
{
if( $maxLength === null )
{
$maxLength = filesize( $filePath );
}
$chunk = 32;
$total = 0;
$handle = fopen( $filePath, "rb" );
if( $handle )
{
fseek( $handle, $offset );
while( feof( $handle ) == false )
{
echo( fread( $handle, $chunk ) );
$total += $chunk;
if( $total >= $maxLength )
{
break;
}
}
fclose( $handle );
}
}
As you can see I have a $chunk variable defined that limits the size of each "packet" pulled from the file, I'm doing this to cap the length of data that can be read. I have a couple of questions regarding this technique:
How much of an impact on server (file system) resources would this have? For example, would it be a big no-no to set the $chunk value to 1.
Would it be bad to cut the stream if it was in the middle of a MP3 or FLV tag?
I have run a little test streaming a standard FLV file from a server, and I am able to seek to any point in the file at any time, but I would like some pointers/tips from PHPers who have had experience with this kind of thing (I don't want to end up killing servers or SWF files etc).
Thanks.
PS: Who needs FMS when you have PHP.
