How to stop PHP Script? [duplicate] How to stop PHP Script? [duplicate] apache apache

How to stop PHP Script? [duplicate]


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


exit(0); or die(); or break; you can use any one.

<?php$i=0;while($i<100) {   mail("xxxxxxx@gmail.com","SPAM","It´s ".date("d.m.o H:i:s");   exit(0);   $i++;}echo "DONE!";

?>

    output: 0   //script is stop after printing 0.


You either use exit() or die() for these purposes. But for your example, this is not really necessary since the script will abort itself after it run.