Kevin Orriss
Kevin Orriss

Reputation: 1032

Kill a php browser request in Linux

I have made a request to a PHP script through my browser to my apache web server. The script is downloading files from an FTP server and it is taking far too long. I think PHP has no timeout set on it so I need to find and kill this browser request.

Any ideas? Thanks

Upvotes: 1

Views: 1581

Answers (1)

Andras
Andras

Reputation: 3055

you can kill the process from the command line if you have root (sudo) access

the running php process will appear as a web server, httpd or apache2. Look for the one that was created the right time ago -- the oldest is the parent process that forks the workers, you want the one that's running the script and not the parent. Ps shows the process creation time and accumulated cpu time, use that to find the right one (I use ps aux | grep apache2, but I'm more used to the BSD toolchain) The ps output includes columns START (process start time, hrs:mins or MonDate) and TIME (cpu time used, min:sec)

% ps aux | grep apache2
root      2641  0.0  0.1  74048 14468 ?        Ss   Feb12   0:27 /usr/sbin/apache2 -k start
www-data  2913  0.0  0.0  74120  6656 ?        S    Feb12   0:00 /usr/sbin/apache2 -k start
andras   32069  0.0  0.0   3560  1792 pts/8    S+   20:57   0:00 grep apache2
www-data 32506  0.0  0.0  74120  6656 ?        S    Feb14   0:00 /usr/sbin/apache2 -k start

I configured apache to start only 2 worker processes. The one owned by root is the master, www-data are the workers. The column headings are

% ps aux | head -1
USER       PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND

You can kill it with any killing signal, but -15 (-TERM) is the usual.

Php does have a default 30-second cpu usage timeout, but an ftp transfer uses very little cpu.

Upvotes: 1

Related Questions