Bram Vanroy Bram Vanroy - 1 year ago 85
PHP Question

Does a PHP process exit when you ctrl + c it from CLI?

I'm witnessing strange disk activity on one of our servers. The only thing I can think of is that during the day a lot of PHP processes were started from CLI in screen mode, like so:

php -f myprocess.php

As soon as I noticed the disk issue, I terminated these processes by attaching the screen, ctrl + c the process, and
ing the screen. I would assume that this exits the PHP process. However, after an hour the disk activity is still very high and obstructively so. (I am no sysadmin so I cannot back-trace the activity.) I know that when you send an ajax request to a server and then abort that request (
), the server will still execute the request. I thought that maybe something similar could be going on when doing a "request" from CLI. The requests are done from home over SSH.

So, did I act correctly and should the processes have stoppped, or is it possible they will run until completion?

Answer Source

Let's construct a little test:

# File: infinite.php
while (true) { sleep(1); }

Run it, then monitor the process:

$ php infinite.php                        # screen one
$ watch -n 1 "ps aux | grep infinite.php" # watch the process (screen two)

Ctrl + C the process in screen one while you watch it from screen two.


The process dies. Ctrl + C kills an active screen's PHP process.

It's possible that you may find the process continues to run if your client terminal simply closes due to a session timeout.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download