I´ve written PHP-Code like this:
<?php
$i=0;
while($i<100) {
mail("[email protected]","SPAM","It´s ".date("d.m.o H:i:s");
$i++;
}
echo "DONE!";
?>
I´ve saved it in the webserver directory. I start it via my browser. How can i stop the script during execution?
Best regards ;)
The exit() function in PHP is an inbuilt function which is used to output a message and terminate the current script. The exit() function only terminates the execution of the script. The shutdown functions and object destructors will always be executed even if exit() function is called.
If you started it in background use ps aux | grep time. php to get PID. Then just kill PID . If process started in foreground, use to interrupt it.
Whenever a PHP application rebuilds MySQL indexes, the process may run for a long time. Generally, allowing a PHP script to run forever is not desirable.
I am aware of exit but it clearly states: Terminates execution of the script. Shutdown functions and object destructors will always be executed even if exit is called.
If you are on UNIX system do this:
ps aux | grep php
it will list all running processes which are instances of php. If you're script is called myscript.php, then you should see php /path/to/myscript.php in this list when it's running.
Now you can kill it by command kill -9 PID
If you're running on windows you can't (unless you can pull up task manager manually) and if you only have web browser access to the server and you're running the script via the web server again you can't kill the process. Either way running an infinite loop script without the ability to kill it on command is a bad idea.
Reference how detect stop or running a php script from out and background
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With