PHP – How do I pass pid from one PHP process to another?

How do I pass pid from one PHP process to another?… here is a solution to the problem.

How do I pass pid from one PHP process to another?

There is a

long-standing PHP process that supports signals (SIGHUP, etc.) and another PHP process that needs to know the PID that is the first to send a signal.

I want to set an environment variable that will be read in the second (client) process and used for my purposes, but putenv(... posix_getpid()...) Doesn’t seem to make it visible to another process.

How do I make environment variables set in one PHP process visible to another? If that’s not possible, what’s the preferred way (I don’t want to use a file or database for this)?

Solution

It is common practice to create a globally known pid file when you start the daemon and write its PID to that file.

Other processes willing to signal the daemon simply read the pid file to retrieve its current pid and subsequently send the signal.

Related Problems and Solutions