Linux – How to view and kill PHP processes

linuxshellssh

I'm very new to using SSH and am having trouble finding a way to view and kill PHP processes that are running.

When I say "PHP processes," I mean PHP files that were started through the browser, but that have continued to run when they were supposed to stop.

I tried this:

ps aux | grep php

But there aren't any results, even though I know the files are running.

How can I view the files that are running and then selectively kill them (or kill them all)?

Best Answer

Htop can be used to view processes and selectively kill them:

sudo apt-get install htop

As ckujau said, it depends on your setup, but typically a new php process is spawned by apache and lives for the duration of a request. In htop, inspect apache while making a request. A php process should start. If it stays alive, you can select and kill it.

Here's a screenshot of htop showing php-fpm processes. php-fpm maintains a pool of long running php processes, able to be reused for multiple requests.

Note 'htop' is a more user friendly version of 'top'.

See also htop explained: https://peteris.rocks/blog/htop/

enter image description here