title: PHP Script watchdog timer
body: <p>To the community,
  I am currently writing a PHP script to serve out files using the standard chunk as such:</p>
  
  <pre><code>set_time_limit(0);
  ob_clean();
  ob_start();
  while (SoapService-&gt;nextChunk()) {
       $chunk=SoapService-&gt;chunk();
       print $chunk;
       ob_flush();
       flush();
  }
  </code></pre>
  
  <p>What I'd like to do is add some sort of method after the flush() like timerReset();
  Then in some sort of timer loop:</p>
  
  <pre><code>while (True) {
     Sleep(0.30);
     if (timerCheckandIncrement() &gt; 100) {
        SoapService-&gt;notifyClose();
        exit(0);
        /*  or  */
        SoapService-&gt;takeSomeAction();
     }
  }
  </code></pre>
  
  <p>This way, if the far end were to stop receiving packets and/or were to become unable to keep up with the stream, I would be able to do things like:
  a)  Change the encoding bitrate.
  b)  Stop the script and clean-up/free-up resources.</p>
  
  <p>I am aware that Apache / PHP can negotiate headers such as Keep-Alive, etc, but I don't know how to exactly leverage them, and/or really make use of them.<br>
  Using an AJAX service would not be preferable.  The objective here is streaming media content from a file server to a mobile device over the internet using an application server.  I have considered writing an "app" as well, but cross-platform coding (android/bb/iOS/W7M) as well as my extremely limited knowledge of SmallTalk (ObjectiveC) would add needless complication.  </p>