I have a Yii2 script that runs forever to execute tasks on request.
Some tasks (as task2
) should be performed in a seperate forked process:
switch ($command) {
case 'task1':
echo "hello";
break;
case 'task2':
if ( ($pid=pcntl_fork()) == -1 )
throw new Exception("fork failed");
if ($pid==0) {
// we are child process
// perform task here
...
exit(0);
}
break;
}
}
Doing such a fork, the database connection goes lost in the parent. There are some workarounds on the PHP level, but how to handle this on the Yii2 level?
Can we activate auto-reconnect in Yii2 by configuration?