title: Trouble with bandwith/memory usage in a php proxy for streaming video
body: <p>I am using a simple (unsafe) php script to stream video through  my server. </p>
  
  <pre><code>&lt;?php
  if(checkToken($_SESSION['token']) &amp;&amp; isLoggedIn() &amp;&amp; checkIsVideo($_GET['url'])){
  
      $dirFile = $_GET['url']; // http://othersite.com/video.mp4
      header("Content-Type: video/mp4");
  
      $fh = @fopen($dirFile, "rb") or die();
      while (!feof($fh)){
          print(fread($fh, 1048576));
          @ob_end_flush();
          @ob_flush();
          @flush();
          @ob_start();
      }
      fclose($fh);
  }
  exit();
  ?&gt;
  </code></pre>
  
  <p>However this php link (<a href="http://mysite123.com/proxy.php?url=othersite.com/video.mp4" rel="nofollow">http://mysite123.com/proxy.php?url=othersite.com/video.mp4</a>) is been used by every single user in my website.</p>
  
  <p>This means that I could have trouble with the memory limit of php, which by the way I know I can change it in "php.ini" file. However, I would like to know a better solution, to make this php proxy script a less consuming task in my server. So that I could, also, handle the bandwidth and pay less ;)</p>
  
  <p>Again, I'm also thinking in building a proxy server only for this "streaming video proxy" task. And that way I can have a website server and a proxy server. Each one capable of managing its traffic.</p>
  
  <p>I guess I could get a proxy server and use a link like:</p>
  
  <p><a href="http://myproxy.com/?url=othersite.com/video.mp4" rel="nofollow">http://myproxy.com/?url=othersite.com/video.mp4</a></p>
  
  <p>I would like to hear your ideas/solutions about this issue.</p>
  
  <p>Thanks :) </p>
  
  <p>EDIT: these video files are usually 150 MB</p>