title: MJPEG Video Stream from a Security Camera using PHP and cURL
body: <p>I have multiple self-hosting network security cameras (Axis 2100, they are pretty old) that I want to broadcast to a website. The cameras support live streaming in MJPG format, but in order to stream the video from these cameras, I must make them public. For security reason, I want to restrict the viewing of these cameras through my website where I can authenticate the users. Since the webcams are on a separate host, I'm using cURL and PHP to log in to the cameras, get the MJPG image stream, and echo the live stream back to be displayed on the webpage. </p>
  
  <pre><code>header('content-type: multipart/x-mixed-replace; boundary=--myboundary');
  
  while (@ob_end_clean()); 
  $ch = curl_init();
      curl_setopt($ch, CURLOPT_URL, 'http://XX.XXX.XXX.XX/axis-cgi/mjpg/video.cgi?resolution=320x240'); 
      curl_setopt($ch, CURLOPT_HEADER, 0);
      curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY | CURLAUTH_ANYSAFE );
      curl_setopt($ch, CURLOPT_USERPWD, 'USERNAME:PASSWORD');
      $im = curl_exec($ch);
  
  
  echo $im;
  curl_close($ch);
  </code></pre>
  
  <p>The problem is when I have multiple sessions of trying to access the same php page with the code above on the same browser, only one session get loaded while the rest remained blank and eventually displayed a 500 internal server error. It works when open it through multiple different browsers, however, with degrade in performance.</p>
  
  <p>Ultimately, I would like to make it a webcam server where I can make one input stream connection from the camera and broadcast it out to multiple clients.</p>
  
  <p>My website is hosted by GoDaddy on a linux server, and I'm not on a dedicated server, so I don't think I get to install any fancy open source video stream hosting server.</p>
  
  <p>Thank You and sorry for such a long post. </p>
  
  <p>-T.Ho</p>