Can PHP tell when the browser goes away?
<p>If I'm generating a stream of data to send out to a browser, and the user closes the browser, can I tell within PHP that I don't need to bother generating or sending the rest of the stream?  I'd like to insert something into this loop:</p>

<pre><code>while (!feof($pipes[1])) {
   echo fgets($pipes[1]);
}
</code></pre>

<p>My fallback plan is to have the browser use a JavaScript onunload to hit another PHP page to kill the process that's generating the data, but it would be cleaner if PHP could tell when I'm echoing to nowhere.</p>
