Jump to content

ReactPHP event loop with periodic timer blocking code after start


Rockerz

Recommended Posts

I am using the ReactPHP event loop with periodic timer. The code works but the browser always shows that the activity is going on (the circle on the chrome tab is always running, refer the link to image below) and it runs only once.

Is it possible to get rid of the running circle and still the periodic loop should run in loop at given intervals to execute the code within the loop. Please advise.

Circle on the tab

Below is my code,

Note: **getAll($temp) is a function with parameter in another .php file. I have got the file as include in my current .php file.

 

$Loop=React\EventLoop\Factory::create(); $Loop->addPeriodicTimer(5, function(React\EventLoop\TimerInterface $timer) use(&$temp, $Loop, &$Total)

{

try{

$Total = getAll($temp);

echo"<script>document.getElementById('Overall').innerText=".$Total."</script>";

}catch (Exception $e){

echo "Error in Loop"; throw $e;

}

});

Link to comment
Share on other sites

If you want to send something to the browser then there must be a connection open. Which is what the spinning circle is telling you.

If you don't want the spinning circle then you need to keep the open connection over something like AJAX or a WebSocket. Which is a different (but better) design than what you have right now.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.