PHP receives a PID system command ()

I am trying to find the PID of a background system call that I am making from a php webpage. If I call "ps -A" from a PHP script and print it in my browser, it does not have the same output as calling "ps -A" from my terminal. This is especially unpleasant because I see the PID of the background process that PHP was calling from my terminal, but not from PHP.

In other words, my code is as follows:

system("process &");
system("ps -A");

But this does not give the same output as calling "ps -A" from the terminal. Not only this, but also the “process” appears in the terminal, but not from calling PHP.

Can someone explain to me why this is so and how I can get the PID of the “process” from my PHP code? (For the record, I also tried using code variations, including using exec () and passthru (), none of which have worked so far.)

Thank.

+3
source share
1 answer
echo $!

will get the PID of the last command, therefore ..

system("process & echo $!");
+2
source

All Articles