I would like to run a background process, which is orphaned, with Symfony Process component. I can't use kernel.terminate event. This is what I have tried to do:
This is process I would like to run:
// script.php
$f = fopen('test'.uniqid().'.txt', 'w');
for ($i = 0; $i < 1000; $i++) {
fwrite($f, "Line $i \n");
sleep(2);
}
fclose ($f);
And this is script which I would like to run my process:
// test.php
$command = "php script.php > /dev/null 2>&1 &";
$p = new \Symfony\Component\Process\Process($command);
$p->start();
echo $p->getPid()."\n";
The problem is that after test.php
termination, script.php
is not working. Termination of main script kills all subprocesses. Is it possible to have orphaned processes running with Symfony Process?