2

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?

WeSee
  • 3,158
  • 2
  • 30
  • 58
  • Yii2 is php freamwork. Everything you can do in php, the same you can do in Yii2. – tigrasti Feb 25 '20 at 08:29
  • @tigrast: How does your comment reflect on my problem? It is neither Yii2 related nor proposes any solution. – WeSee Feb 25 '20 at 09:01

0 Answers0