📌  相关文章
📜  pcntl_fork php mysql "MySQL 服务器已消失" - PHP 代码示例

📅  最后修改于: 2022-03-11 14:53:35.981000             🧑  作者: Mango

代码示例1
$model_mod = new Model_Base();
                        $model_mod->disconnect();
                        $pid = pcntl_fork();
                        //Both the parent process and the child process will execute the following code
                        if ($pid == -1) {
                            //Error handling: return -1 when failed to create a child process.
                            die('could not fork');
                        } else if ($pid) {
                            $model_mod->connect();
             
                            //The parent process will get the child process number, so here is the logic executed by the parent process
                            pcntl_wait($status); //Wait for the interruption of the child process to prevent the child process from becoming a zombie process.
                        } else {
                            
                            //The $pid obtained by the child process is 0, so here is the logic executed by the child process.
                        }