3

I have an Apache server running a web application. In this webapplication I show a video using JWPlayer. JWPlayer uses http pseudostreaming to fetch the video from a PHP script which serves up this video. All this works well and the video is streamed well.

The problem I am having is while the video is streaming I also use AJAX calls to fetch some XML files which are used by Adobe Flash files on the same page. While streaming these XML file fetches are kept 'pending' until the entire video is loaded. Using Chrome I can see that the video gets loaded byte by byte. When the video is entirely loaded, then the XML files are fetched. Also if I open another tab in my browser while a video is streaming and try to load the web application again, it will also not show until the video is entirely loaded.

This seems te be an Apache setting of some sort. The MPM settings for apache are:

ThreadsPerChild 150 MaxRequestsPerChild 0

This seems to be correct. Any ideas what could be wrong?

CptEO
  • 33
  • 2
  • My guess: maybe Flash uses the browser's XMLHTTPRequest object to handle the HTTP pseudostreaming. That could block the object from being available for other requests. – Matt S Aug 21 '12 at 13:59
  • Maybe `Keep-alive` is the problem? What's the value of it in `httpd.conf`? – s.webbandit Aug 21 '12 at 14:01
  • Timeout 300 KeepAlive On MaxKeepAliveRequests 100 KeepAliveTimeout 5 – CptEO Aug 21 '12 at 14:11

2 Answers2

2

If you are using PHP sessions then this is probably what is causing the IO blocking.

php blocking when calling the same file concurrently

Community
  • 1
  • 1
Imre L
  • 6,159
  • 24
  • 32
  • Thanks! Adding session_write_close() before outputting the video contents did the trick. – CptEO Aug 21 '12 at 14:15
0

I was making a system with private video streaming. So, i was needing a streaming via php, because using php programming i was able to restringe user access.

I was having troubles to streaming video and execute other script on the server. Using the session_write_close() solve the problem to open another scripts and i found that script on web that helps me sooooo much.

I want to share, because that script makes a real streaming. I found it on http://www.tuxxin.com/php-mp4-streaming/ website. All thanks to the author of this code =D

ENJOY !

<?php
$file = 'video360p.mp4';
$fp = @fopen($file, 'rb');
$size   = filesize($file); // File size
$length = $size;           // Content length
$start  = 0;               // Start byte
$end    = $size - 1;       // End byte
header('Content-type: video/mp4');
//header("Accept-Ranges: 0-$length");
header("Accept-Ranges: bytes");
if (isset($_SERVER['HTTP_RANGE'])) {
    $c_start = $start;
    $c_end   = $end;
    list(, $range) = explode('=', $_SERVER['HTTP_RANGE'], 2);
    if (strpos($range, ',') !== false) {
        header('HTTP/1.1 416 Requested Range Not Satisfiable');
        header("Content-Range: bytes $start-$end/$size");
        exit;
    }
    if ($range == '-') {
        $c_start = $size - substr($range, 1);
    }else{
        $range  = explode('-', $range);
        $c_start = $range[0];
        $c_end   = (isset($range[1]) && is_numeric($range[1])) ? $range[1] : $size;
    }
    $c_end = ($c_end > $end) ? $end : $c_end;
    if ($c_start > $c_end || $c_start > $size - 1 || $c_end >= $size) {
        header('HTTP/1.1 416 Requested Range Not Satisfiable');
        header("Content-Range: bytes $start-$end/$size");
        exit;
    }
    $start  = $c_start;
    $end    = $c_end;
    $length = $end - $start + 1;
    fseek($fp, $start);
    header('HTTP/1.1 206 Partial Content');
}
header("Content-Range: bytes $start-$end/$size");
header("Content-Length: ".$length);
$buffer = 1024 * 8;
while(!feof($fp) && ($p = ftell($fp)) <= $end) {
    if ($p + $buffer > $end) {
        $buffer = $end - $p + 1;
    }
    set_time_limit(0);
    echo fread($fp, $buffer);
    flush();
}
fclose($fp);
exit();
?>
dudow8
  • 19
  • 3