Jump to content

Breaking an Infinite Loop when User Disconnects?


tommyboy123x

Recommended Posts

I'm not sure what PHP considers an "aborted connection" and things like that, but the way this chat works is by updating a file and using the timestamp off it to determine if new posts exist.  Rather than re-checking the server over and over, this code will check once and keep the connection open until a response is made.  The only problem is, it works too well!  Even after the tab is closed and I try another script on the site or the same script, it all hangs until I update the file - here is the code snippet:

 

while (($currentmodif <= $lastmodif) && (connection_aborted() == 0) && (connection_status() == 0)){ // check if the data file has been modified

    usleep(10000); // sleep 10ms to unload the CPU
    if (connection_aborted ()) break;
    if (connection_status () != 0) break;
    clearstatcache();
    $currentmodif = filemtime($filename);
    }

 

I have put several measures in to attempt to break the loop when the user disconnects, but it just doesn't work!  It will continue to hang and hang and hang until I re-upload the file $filename

 

HOW CAN I BREAK THE WHILE LOOP WHEN THE MEMBER LEAVES THE PAGE?

 

I could post up an example but its ultimately useless after one load unless you have control over updating the file.

 

Thanks!

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.