0

i have a (process) php code which run background which listening to incoming.
and i wanna have another (admin) php code for admin use which i can start and stop the 1st (process) php code.

starting the (process) php code is easy with exec(/usr/php5/bin/php my_process_code.php);
but how can i stop/kill the (process) php code?

4
Contributors
3
Replies
4
Views
9 Years
Discussion Span
Last Post by helraizer
0

first terminate the process using the process_terminate function after close the process using the process_close even u can get the exit code of the process

0

Hello,

You're best off using something like this to launch your other process:

$pid = shell_exec("nohup $Command > /dev/null 2>&1 & echo $!");

where $Command is the command executed be it php /path/to/file.php etc..

That there would execute the process, and give you a running process ID.

You can then test to see if its running by executing ps $pid - and looking at the return:

exec("ps $pid", $pState);
      $running = (count($pState) >= 2);

to terminate you can always use exec("kill $pid");

However, you cant kill processes not owned by the user PHP runs at - if it runs as nobody - you'll start the new process as nobody, and only be able to kill processes running under the user nobody.

Hope that makes some sense?

Kind Regards,
Dan

0

If you opened said first process with

proc_open() then you can use the function proc_close() to stop it running again.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.