tommyboy123x Posted April 18, 2011 Share Posted April 18, 2011 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! Quote Link to comment https://forums.phpfreaks.com/topic/234017-breaking-an-infinite-loop-when-user-disconnects/ Share on other sites More sharing options...
tommyboy123x Posted April 18, 2011 Author Share Posted April 18, 2011 Eureka! I found out you need to send something to the browser in order to check if it is still alive - I chose "echo chr(0);" but you can also use echo "\n"; from what I hear. Tom Quote Link to comment https://forums.phpfreaks.com/topic/234017-breaking-an-infinite-loop-when-user-disconnects/#findComment-1202817 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.