0

I've been following some tutorials on running and managing php scrips as background process. I've been playing with the script below.

<?php
$count = 0;
while(true){
    $count = $count + 1;
    file_put_contents('daemon1.log', $count, FILE_APPEND);
    sleep(1);

}
?>

When I run this navigating to it's url in a browser window and I then close the window it seems to keep running. Is this typical of php scripts? How do I stop this process once it's running int he background?

Ben Pearce
  • 6,884
  • 18
  • 70
  • 127
  • Yes it is typically the basic behaviour, but know that there is a execution time limit (with a default value to 30s) that can be changed with `set_time_limit` function – MatRt May 20 '13 at 04:55

2 Answers2

0

When I run this navigating to its URL in a browser window and I then close the window it seems to keep running. Is this typical of PHP scripts?

It will keep running because it's still working.

It will die when a maximum execution time or memory limit is hit.

How do I stop this process once it's running in the background?

To stop it, use a construct such as exit.

alex
  • 479,566
  • 201
  • 878
  • 984
  • You are not really responding to the question. He don't ask how to stop the script, he ask how to stop the script when the client disconnect to the server – MatRt May 20 '13 at 04:53
  • @MatRt *he ask how to stop the script when the client disconnect to the server* Where was that mentioned in the question? – alex May 20 '13 at 06:12
0

Yes it is typically the basic behaviour, but know that there is a execution time limit (with a default value to 30s) that can be changed with set_time_limit function

If you want to manage that kind of configuration, take a look at

ignore_user_abort

that will allow you to configure if you want to ignore or not user abort. You can also check the client status with

connection_aborted

connection_aborted documentation

ignore_user_abort documentation

MatRt
  • 3,494
  • 1
  • 19
  • 14