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?

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

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

If you opened said first process with

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