In web.php I start the process in this route
Route::get('/startProcess',function(){
$descriptorspec=.......
$process1 = proc_open('php C:\Process1.php',$descriptorspec,$pipes);
// Here I need to save a reference to the process - $process1
});
I need to close this process in another route
Route::get('/stopProcess',function(){
// Here I need to get a reference to the process - $process1
proc_close( $process1 )
});
Where do I save a reference to the process and how do I get it ?
proc_openreturns a resource, and resources can't be serialised so I don't think you can retrieve the resource again after the request ends.Here is a potential solution:
Then you can use the PID retrieved to kill the process using a shell operation:
You can call the later as
https://example.com/stopProcess/12345