title: Streaming video with PHP from server
body: <p>I need to stream selected video files on the web server to clients.  I am using a PHP script to stream these files as requested, but I am running into an issue where if I am on a local net, it works fine, but if I am remote, it stutters. eg. it appears to load the stream, stop, load more, stop, etc. until enough media is available to play.  I am new to this stuff, so I need some advise on how to overcome this issue.  The bandwidth should not be a problem, so I am not sure what is going on.  I have tried several php streamers, but all act pretty much the same.  I am using videojs to display it within the client.</p>
  
  <pre><code>&lt;?php
  use vendor\videojswidget\VideoJsWidget;
  $url = Yii::$app-&gt;urlManager-&gt;createUrl('/site/putvideo');
  $currentVideo = '';
  $script1 = "function playAnotherVideo(){
      var source = document.getElementById('fileSelector');
      var path = source.value;
      $.ajax({
          type: 'post',
          data: {file: path},
          url: '" .$url. "',
          success: function(result){
              var video = document.getElementById('videoPlayer');
              video.src = result;
              alert(result);
              video.load();
          },
          error: function(){
              alert('error');
          }
      });
  }";
  
  $this-&gt;registerJs($script1, yii\web\View::POS_END, 'my-options');
  
  /* @var $this yii\web\View */
  
  $this-&gt;title = 'View Vault Lecture Capture System';
  ?&gt;
  &lt;div class="site-index" style="background-color: black; color: yellow;"&gt;
  
      &lt;div style="background-color: black;"&gt;  
          &lt;/br&gt;&lt;/br&gt;&lt;/br&gt;&lt;/br&gt;     
          &lt;h1 align="center"&gt;Welcome to the TEKVOX Lecture Capture System&lt;/h1&gt;
          &lt;/br&gt;&lt;/br&gt;&lt;/br&gt;&lt;/br&gt; 
      &lt;/div&gt;
      &lt;div class="body-content"&gt;
          &lt;div style="width: 100%; overflow: hidden;"&gt;
          &lt;div style="width: 50px; float: left;"&gt;
          &lt;/br&gt;&lt;/br&gt;
          &lt;label for="fileselector" style="margin-left: 4em; width: 10em; 
              font-weight: bold; color: #FFFF00;"&gt;Video_Files&lt;/label&gt;
          &lt;select id="fileSelector" onchange="playAnotherVideo()" size="10em" 
          style="margin-left: 0em; color: #FFFF00; background-color: #000000; 
          border-color: #FFFFFF"&gt;
  &lt;?php
          if ($handle = opendir('c:/users/admin/videos/')) {
  
              while (false !== ($entry = readdir($handle))) {
  
                  if ($entry != "." &amp;&amp; $entry != ".." &amp;&amp; 
                      strtolower(substr($entry, strrpos($entry, '.') + 1)) == 
                         'mp4' ){       
                      echo "&lt;option value='$entry'&gt;" .$entry. "&lt;/option&gt;";
                  }
              }
  
              closedir($handle);
          }
  ?&gt;
  &lt;/select&gt;
  &lt;/div&gt;
  &lt;span id="divplayer" style="margin-left: 20em;"&gt;
  &lt;?php
  
  echo VideoJsWidget::widget([
      'options' =&gt; [
          'class' =&gt; '',
          'id' =&gt; 'videoPlayer',
          'poster' =&gt; "GreenX.png",
          'controls' =&gt; true,
          'preload' =&gt; 'none',
          'width' =&gt; '800',
          'height' =&gt; '450',
      ],
      'tags' =&gt; [
          'source' =&gt; [
              ['src' =&gt; '', 'type' =&gt; 'video/mp4'],
          ],
          'track' =&gt; [
              ['kind' =&gt; 'captions', 'src' =&gt; 
  'http://vjs.zencdn.net/vtt/captions.vtt', 'srclang' =&gt; 'en', 'label' =&gt; 
  'English']
          ]
      ]
  ]); 
  
  ?&gt;
          &lt;/span&gt; 
      &lt;/div&gt;
  &lt;/div&gt;
  &lt;/br&gt;
  </code></pre>
  
  <p>The getVideo.php code:</p>
  
  <pre><code>&lt;?php
  include_once "videoStream.php";
  $filename = $_GET['filename'];
  if($filename == '')
      return;
  $file = "c:\\users\\admin\\videos\\" .$filename;
  
   $stream = new VideoStream($file);
   $stream-&gt;start();
  </code></pre>
  
  <p>?></p>
  
  <p>The VideoStream.php class I am currently trying out is at:
  <a href="https://gist.github.com/ranacseruet/9826293" rel="nofollow noreferrer">VideoStream</a></p>
  
  <p>What is also strange is that the bar at the bottom of the player seems to indicate that the video is buffered, yet the player still stutters.  Not sure what that means.</p>