0

I need to make application in PHP which will work in while loop, and listen to connection and if I send signal for stop, it will stop while loop.

For example:

<?PHP
set_time_limit(0);
$i=0;
while ($i <= 2000){

// Listen for connection = Kill signal
// For example:
//   if signal is received{
//   break; 
//   }

$i++; // Count
usleep(2000);
}

?>

So if I have web interface with stop button, I wanna be able to stop while loop when I click on that stop button.

xZero
  • 645
  • 2
  • 9
  • 24
  • is this possible? You most likely best way would use js since it is client-side and php is server-side. – Class Jan 31 '13 at 17:47
  • Not possible. The php-code is evaluated on the server **before** it is being sent out. – fragmentedreality Jan 31 '13 at 17:51
  • Similiar: http://stackoverflow.com/questions/11705357/how-to-listen-muliple-tcp-streams-continously-by-stream-get-contents Possible to done it like that? – xZero Jan 31 '13 at 18:00

1 Answers1

1

PHP is evaluated on the server-side and therefore, client-side bindings cannot emit changes in the control flow in PHP.

Your best bet would be to implement something like this in Javascript, binding the button press to a defined event that would stop the loop there.

Daniel Li
  • 14,976
  • 6
  • 43
  • 60
  • This is similiar: http://stackoverflow.com/questions/11705357/how-to-listen-muliple-tcp-streams-continously-by-stream-get-contents Is that possible? – xZero Jan 31 '13 at 17:59