How do I stop a PHP script?
I wrote PHP code like this:
<?php
$i=0;
while($i<100) {
mail("xxxxxxx@gmail.com","SPAM","It´s ".date("d.m.o H:i:s");
$i++;
}
echo "DONE!";
?>
I saved it in the web server directory. I am running it through my browser. How can I stop the execution of a script in time ?
Respectfully;)
source to share
If you are on a UNIX system, do the following:
ps aux | grep php
it will list all running processes which are php instances. If your script is called myscript.php then you should see php / path / to / myscript.php in this list when you run it.
Now you can kill him with the command kill -9 PID
If you are on Windows you cannot (unless you can manually open the task manager) and if you only have access to the web browser on the server and you run the script again through the web server you again cannot kill the process ... Anyway, running an infinite loop of a script without being able to kill it on command is a bad idea.
Link how to detect stopping or starting php script from background and background
source to share