Welcome Guest, Not a member yet? Register   Sign In
Infinite long polling
#1

[eluser]Unknown[/eluser]
Hello people!

I'm doing some ajax long polling request on a page of my website, when i call this page it launches a new thread asynchronously.

The problem is, when i leave this page, the thread obviously continues its execution, and when i go back to this page, it launches a new one. So my question is, how can a stop the execution of the thread when i leave the page that is executing it ?
I cannot set a timeout since it is a long polling request.

Here is my code :

The javascript in my client view:
Code:
[removed]
$(document).ready( function() {
      connect();
   });

function connect()
{
var urlCall = "<?=base_url() ?>operation/reload/";
$.ajax({
       url: urlCall,
       dataType: 'json',
       cache   : false,
       success: function(data) {
                 /* doing some stuff */
           connect();
     }
});
}
[removed]

And the controller "operation" called :
Code:
function reload(){
  while(true){
   log_message('debug','reloading table');
   $newValue = $this->user->getValue();
   if($newValue != $currentValue){
    $variable['value']=$newValue;
    echo json_encode($variable);
    break;    
   }
   sleep(5);
  }
}

Thanks for your help
#2

[eluser]InsiteFX[/eluser]
Maybe you should read up a language before using it!

See: complete
#3

[eluser]Unknown[/eluser]
Pardon my ignorance, i don't know what you had in mind or if i made an obvious mistake writing the post but i don't think the problem comes from the ajax part.

Canceling the request will not cancel the php loop.

Here is a similar thread on stackoverflow that might explain my problem better. However i would like to stop my loop whenever the view is not visible.


Thanks




Theme © iAndrew 2016 - Forum software by © MyBB