Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can't kill PHP script

Tags:

linux

php

ssh

I am developing some PHP scripts on a Namecheap shared server. I accidentally made a loop which seems to go on indefinitely (or for a very long time), so now I am trying to kill it using SSH.

I have viewed a list of running processes with top, found the misbehaving PHP script, and tried to kill it with kill. However, after I kill it with this command, when I try using the ps, it is still running!

The result of the ps:

   PID TTY      STAT   TIME COMMAND
819520 ?        S      0:00 /usr/bin/php /my/php/file.php

I have tried killing the process over and over, but it just won't die!

The SSH is limited, so I can't use commands like killall. What do I do??!

like image 365
tomb Avatar asked Aug 06 '13 08:08

tomb


People also ask

How do you stop a PHP file from running?

Try running something like apachectl stop and then apachectl start to start it back up. This will kill your server for a period of time but it will also make sure that any processes stuck on that script will go away.

How do I close a PHP server?

The best way is to close the terminal window as we cannot type anything while the server is running! Press the (X) button on the top right(on Windows/Linux)/Press the red color circle on the top left(on Mac OS) of the terminal window to stop the PHP server from running.

How can I see what processes are running PHP?

Depending on your setup this could be managed via fast-cgi or mod_php or even php-fpm. If you use mod_php , then there will be no "php processes" visible for ps . You can still see if your PHP engine is in use by using lsof : $ lsof -ln [...]


1 Answers

To kill the process you can do the following:

  • Get the PID with ps -ef
  • kill it with kill -9 <pid>

A nice reference: When should I use kill -9?

Just for fun, an example:

$ sleep 100 &
[1] 4156
$ ps -ef | grep slee[p]
me    4156  3501  0 10:34 pts/5    00:00:00 sleep 100
$ kill 4156
[1]+  Terminated              sleep 100
$ ps -ef | grep slee[p]
$
like image 69
fedorqui 'SO stop harming' Avatar answered Sep 30 '22 06:09

fedorqui 'SO stop harming'