Debian OS 7.
How to check if there is a process in the system? If there is no process, then start the process.
I am not familiar with PHP, I ask your help. File path xxx
Addition:
There is a client and a remote machine (VDS). The client program should send the machine a command to start the file, first checking whether such a process is already running.

  • Are you sure that it is advisable to do this using php? - Artem Y
  • Well, do not use SSH for the sake of one command? What can you offer? - Konstantin
  • Aah, I probably should add - I forgot. There is a client program and a server, so the client should make a request to the server and start the process. - Konstantin
  • I just need a PHP script that will be on the machine that I need to call from the client. There are no problems with invoking scripts from the client. There is a problem with writing a PHP script - Konstantin

1 answer 1

Run script from console

exec('php cli.php', $m); 

Get process ID (check for uniqueness)

 $pid = getmypid(); 

View a list of all processes with pid from php (not all console commands work)

 exec('ps aux', $m); echo '<pre>'; var_dump($m); echo '</pre>'; 

And the answer to your question: how to start with the assignment of a name so that you can then control:

 $pid = getmypid(); $title = "my_php_s"; if (!cli_set_process_title($title)) { echo "Unable to set process title for PID $pid...\n"; exit(1); } else { echo "The process title '$title' for PID $pid has been set for your process!\n"; sleep(5); } 

But this particular code only from the console will work, and you need to accept the http server’s remote server command as API