The MySQL server has gone away error pcntl_fork before the database is connected. The reason is that the child process inherits the database connection from the main process, and when MySQL returns the data, these sub-processes can read the data through the connection, causing the data to be garbled.
The operation of the database is the place to operate the database, to solve this problem, in $pid = pcntl_fork(); Before clearing out the MySQL connection before
Interpretation of official documents and solutions
http://php.net/manual/en/function.pcntl-fork.php#70721
So I try, gee, or not AH ~ ~ ~ again look at the code, found something wrong ~ ~ to $pid = pcntl_fork () before the MySQL connection is cleared, why the above code is $db = mysql_connect ( $server , $username , $password
So, I am in $pid = pcntl_fork(), before change to Disconnet ~
$model _mod=Newmodel_base (); $model _mod->disconnect (); $pid=pcntl_fork (); //both the parent and child processes execute the following code if($pid= =-1) { //error Handling: Returns -1 when creating a child process failure. die(' could not fork '); } Else if($pid) { $model _mod->connect (); //The parent process gets the child process number, so this is the logic that the parent process executesPcntl_wait ($status);//wait for the child process to break to prevent the child process from becoming a zombie process. }Else { //the child process gets a $pid of 0, so here is the logic that the child process executes. }
Finally successfully solve the problem ~ ~
Pcntl_fork causes MySQL server has gone away solution