Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to kill all PHP-FPM processes in a single command line

Tags:

linux

php

process

I have a challenge shutting down effectively php-fpm; not all processes stop running and as such, php-fpm does not restart as expected.

I want a command line to run that will kill all the php-fpm process so I can add it to init.d so a stop will ensure they are all removed.

Below is the result of ps -aux | grep php-fpm;

793      102971  0.0  0.1 4520304 5868 ?        S    13:20   0:00 php-fpm: pool tokyodating.co
794      102972  0.0  0.1 4520304 5868 ?        S    13:20   0:00 php-fpm: pool turkeydating.co
794      102973  0.0  0.1 4520304 5868 ?        S    13:20   0:00 php-fpm: pool turkeydating.co
794      102974  0.0  0.1 4520304 5868 ?        S    13:20   0:00 php-fpm: pool turkeydating.co
795      102975  0.0  0.1 4520304 5868 ?        S    13:20   0:00 php-fpm: pool ukrainedating.co
795      102976  0.0  0.1 4520304 5868 ?        S    13:20   0:00 php-fpm: pool ukrainedating.co
795      102977  0.0  0.1 4520304 5868 ?        S    13:20   0:00 php-fpm: pool ukrainedating.co
796      102978  0.0  0.1 4520304 5868 ?        S    13:20   0:00 php-fpm: pool unemployeddating.com
796      102979  0.0  0.1 4520304 5868 ?        S    13:20   0:00 php-fpm: pool unemployeddating.com
796      102980  0.0  0.1 4520304 5868 ?        S    13:20   0:00 php-fpm: pool unemployeddating.com
822      102981  0.0  0.1 4520304 5868 ?        S    13:20   0:00 php-fpm: pool datingcougar.co
822      102982  0.0  0.1 4520304 5868 ?        S    13:20   0:00 php-fpm: pool datingcougar.co
822      102983  0.0  0.1 4520304 5888 ?        S    13:20   0:00 php-fpm: pool datingcougar.co
798      102984  0.0  0.1 4520304 5888 ?        S    13:20   0:00 php-fpm: pool vegandating.co
798      102985  0.0  0.1 4520304 5888 ?        S    13:20   0:00 php-fpm: pool vegandating.co
798      102986  0.0  0.1 4520304 5888 ?        S    13:20   0:00 php-fpm: pool vegandating.co
799      102987  0.0  0.1 4520304 5888 ?        S    13:20   0:00 php-fpm: pool vegetariandating.co
799      102988  0.0  0.1 4520304 5888 ?        S    13:20   0:00 php-fpm: pool vegetariandating.co
799      102989  0.0  0.1 4520304 5888 ?        S    13:20   0:00 php-fpm: pool vegetariandating.co
800      102990  0.0  0.1 4520304 5888 ?        S    13:20   0:00 php-fpm: pool vietnamdating.co
800      102991  0.0  0.1 4520304 5888 ?        S    13:20   0:00 php-fpm: pool vietnamdating.co
800      102992  0.0  0.1 4520304 5888 ?        S    13:20   0:00 php-fpm: pool vietnamdating.co
720      103001  0.0  0.2 4522680 10672 ?       S    13:21   0:00 php-fpm: pool kuwaitdating.co
746      103008  0.1  0.2 4522684 10132 ?       S    13:23   0:00 php-fpm: pool newzealanddating.co
746      103009  0.0  0.1 4520304 5876 ?        S    13:23   0:00 php-fpm: pool newzealanddating.co

How can I kill all php-fpm processes running a single command line?

like image 598
Adam Avatar asked Mar 06 '14 05:03

Adam


People also ask

How do I stop a PHP script from running in the background?

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.

What is PHP-FPM command?

PHP-FPM is a service which executes PHP code on behalf of a web server. As NGINX is unable to natively execute PHP code, it can be onfigured to pass all . php files over to PHP-FPM.

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 [...]

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.


3 Answers

You can use killall instead, it takes a process name instead of a PID

killall -KILL php-fpm

ps: -9 and -KILL are the same

like image 87
Mohammad AbuShady Avatar answered Nov 13 '22 08:11

Mohammad AbuShady


if who get problem like me:

-bash: killall: command not found

you can use:

sudo kill -9 `sudo ps -ef | grep php-fpm | grep -v grep | awk '{print $2}'`

I found this command here: https://gist.github.com/bmichalski/c8d25fff041a4739d6f0126edb0e9b54 , it worked for me.

like image 43
Bảo Nam Avatar answered Nov 13 '22 07:11

Bảo Nam


If you are having issues where killall is not a command on your environment, I would recommend the following:

To kill all php-fpm for your user

pkill php-fpm

To kill all php-fpm for all users

sudo pkill php-fpm
like image 21
hotline_emu Avatar answered Nov 13 '22 07:11

hotline_emu