Hubro
Hubro

Reputation: 59408

How to start a PHP process with a name?

I have a PHP script that spawns between 10 and 100 PHP scripts to help share the load of some calculations.
The problem is that this parent PHP script starts in the background and runs for ever, so it has to be shut down at some point. It can be an arduous task to blindly shut down PHP processes until you hit the parent.

Is there some way I can start the parent PHP process with a unique name such as "Ping loop", or some other way of recognizing it in the top interface?


I am aware of the alternative of creating a Daemon or a shutdown script using the PID of the parent. I'm asking this question hoping to avoid having to do that.

Upvotes: 3

Views: 2180

Answers (3)

ekowabaka
ekowabaka

Reputation: 21

You can use the setproctitle() functions which comes with the proctitle pecl extension. This function sets a title for your php scripts so you can easily identify them.

You can read more from http://www.php.net/manual/en/function.setproctitle.php

Upvotes: 2

binaryLV
binaryLV

Reputation: 9122

I would store value of getmypid() into a file, when parent script starts. That's also what I've seen other programs doing, e.g., apache by default stores PID of its main process in /usr/local/apache2/logs/httpd.pid.

Upvotes: 3

Sander Marechal
Sander Marechal

Reputation: 23216

Check what the top level PHP script is using ps axuf or a similar command.

Upvotes: 4

Related Questions