Re: Blocking video streaming

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Talawa a écrit :
Kim Madsen a écrit :
Hey

Talawa wrote on 2009-10-19 18:29:
Hello everyone,

I post a message here because i didn't find any solution yet.
I just finished video streaming service on my website. I use xmoov script (http://xmoov.com/xmoov-php/) to do that. It works like a charm, but I find an issue. When the video is buffering into the flash player, all others requests are pending until the video is loaded.

I discovered in my search that fopen() function could block php process.

Does someone know this problem ?

I've had a similar problem with zip downloads (which also use fopen), I supect either the headers, a caching problem or latin1/utf-8

What does your headers look like? (firefox has a lovely plugin "live http headers")

Which character encoding do you use?

Show us code bit from fopen to fclose

I forced charset encoding in my htaccess to ISO-8859-1.

Here's the http headers I receive :
Expires: Thu, 19 Nov 1981 08:52:00 GMT
Cache-Control: no-store, no-cache, must-revalidate, post-check=0,
pre-check=0, max-age=0
Pragma: no-cache
Last-Modified: Mon, 19 Oct 2009 19:00:33 GMT
X-Pad: avoid browser bug
Content-Length: 14145470
Vary: User-Agent
Keep-Alive: timeout=5, max=100
Connection: Keep-Alive
Content-Type: video/x-flv

And here's the php code :
if (($fh = fopen($file, 'rb')) === FALSE)
       return;

# assemble packet interval
$packet_interval = 0.3;

# assemble packet size
$packet_size = STREAM_SPEED * 1042;

$seekPos = intval($seekPos);
$fileSize = filesize($file) - (($seekPos > 0) ? $seekPos  + 1 : 0);

session_cache_limiter("nocache");
header("Cache-Control: private",false);
header("Expires: Thu, 19 Nov 1981 08:52:00 GMT");
header("Last-Modified: " . date("D, d M Y H:i:s") . " GMT");
header("Cache-Control: no-store, no-cache, must-revalidate,
post-check=0, pre-check=0, max-age=0");
header("Pragma: no-cache");
header("Content-Type: video/x-flv");
header("X-Pad: avoid browser bug");
header("Content-Length: " . $fileSize);
# FLV file format header
if($seekPos != 0)  {
       print('FLV');
       print(pack('C', 1));
       print(pack('C', 1));
       print(pack('N', 9));
       print(pack('N', 9));
}

# seek to requested file position
fseek($fh, $seekPos);

# output file
while(!feof($fh)) {
       # get start time
       list($usec, $sec) = explode(' ', microtime());
       $time_start = ((float)$usec + (float)$sec);
       # output packet
       print(fread($fh, $packet_size));
       # get end time
       list($usec, $sec) = explode(' ', microtime());
       $time_stop = ((float)$usec + (float)$sec);
       # wait if output is slower than $packet_interval
       $time_difference = $time_stop - $time_start;
       if($time_difference < (float)$packet_interval) {
usleep((float)$packet_interval * 1000000 - (float)$time_difference * 1000000);
       }
}
fclose($fh);


Thanks for help.

I solve the issue. I forgot to close the session before sending the stream.
Add session_write_close(); before sending.

In hope it may help.

Cheers.

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux