每个子进程都需要一个自己的数据库连接 代码如下
<?php
// Create the MySQL connection
$db = mysql_connect($server, $username, $password);
$pid = pcntl_fork();
if ( $pid == -1 ) {
// Fork failed
exit(1);
} else if ( $pid ) {
} else {
$host = '主机地址';
$username = '用户名';
$password = '密码';
$database = '数据库';
$connection = mysqli_connect($host, $username, $password, $database);
if (!$connection) {
die("无法连接到数据库: " . mysqli_connect_error());
}
unset($connection );
exit(0);
?>