Gossamer Forum
Home : General : Internet Technologies :

PHP Streaming

Quote Reply
PHP Streaming
Code:
function display_video($file, $mime) {
ob_start();
$fp = fopen($file, "rb");
$file_info = pathinfo($file);
$file_size = filesize($file);
header("Content-type: $mime");
header("Content-Length: " . $file_size);
while(! feof($fp)) {
set_time_limit(0);
print(fread($fp, 2048));
flush();
ob_flush();
}
fclose($fp);
exit;
}
This PHP function will output a video file. However, not until entire file read. Should stream the file, but cannot seem to get it work. Any ideas?

----
Cheers,

Dan
Founder and CEO

LionsGate Creative
GoodPassRobot
Magelln
Quote Reply
Re: [dan] PHP Streaming In reply to
From the recent research I've done to try and get a video file to play within my database I read that when the metadata is at the end of the file then it has to read the whole file before it will play.

Someone wrote a program that will quickly move the metadata to the beginning of the file(s) so it will stream the videos.

Check out MetadataMover at: http://rndware.info/content/MetadataMover

You can also test whether the video has metadata using this link: http://home5.inet.tele.dk/nyboe/flash/online_meta_data.htm

Hope this helps :)

Unoffical DBMan FAQ

http://creativecomputingweb.com/dbman/index.shtml/
Quote Reply
Re: [LoisC] PHP Streaming In reply to
Thanks for the response! I have discovered more since then. The problem only relates to WMV files. Other files like MPG will play, but after full download as they are not pseudo-streaming video types. That is okay. The WMV files will stream if called elsewhere in normal way via in-page scripting. But, if same WMV files are played via that PHP file, they not only do not stream, they do not play at all - produce codec error. So, question is why do WMV files not play, and result in the codec error. I checked, no headers are sent before video headers sent. Happens with both IE and FF.

----
Cheers,

Dan
Founder and CEO

LionsGate Creative
GoodPassRobot
Magelln
Quote Reply
Re: [dan] PHP Streaming In reply to
Perhaps you're not providing the correct headers that the player is expecting for it to stream (eg. maybe you're missing the file length, or some other header). Compare the headers being sent for the same file, one being a regular file on the webserver, and one through your script.

Adrian
Quote Reply
Re: [brewt] PHP Streaming In reply to
From my research, I seem to be passing the correct headers including file size. How can I examine headers of the file pulled directly from server?

----
Cheers,

Dan
Founder and CEO

LionsGate Creative
GoodPassRobot
Magelln
Quote Reply
Re: [dan] PHP Streaming In reply to
Update: I think I may have found solution. I added:

header("Connection: keep-alive");

Seems to work now. Still testing.

----
Cheers,

Dan
Founder and CEO

LionsGate Creative
GoodPassRobot
Magelln