PHP script with sleep() does not exit on connection close
<p>I have a PHP script that does this:</p>

<pre><code>$sec = 1;
$id = 1;
while ($sec&lt;20) {
    sleep(1);
    mysql_query("update test set sec = $sec where id = $id");
    $sec++;
}
</code></pre>

<p>Whenever I load the script in my browser, it will keep on going even if I closed the browser window after 5 seconds. How can I change this so when the browser window is closed, the script will exit?</p>
