init(new room\room_processor()); room\room_server::instance()->run_loop($sockfd); } function fork_subprocess($count,$listen_fd) { if (($pid = pcntl_fork()) === 0) { //ob_end_clean(); // Discard the output buffer and close fclose(STDIN); // Close all of the standard fclose(STDOUT); // file descriptors as we fclose(STDERR); // are running as a daemon. Log::record("pid = {$pid} count = {$count} ",Log::DEBUG); search_work($listen_fd); exit(); } elseif($pid === -1) { Log::record("pid = {$pid} count = {$count} ",Log::DEBUG); die('could not fork'); } else { Log::record("pid = {$pid} count = {$count} ",Log::DEBUG); $ret = pcntl_waitpid($pid,$status,WNOHANG); if($ret == 0) { Log::record("spawn-fcgi: successful ret == 0 PID: {$pid}",Log::DEBUG); } elseif($ret == -1) { Log::record("spawn-fcgi: ret == 0 PID: {$pid}",Log::DEBUG); } else { Log::record("spawn-fcgi: ret == 0 child exited PID: {$pid}.",Log::DEBUG); } } } global $config; $host = $config['room_srv']['host']; $port = $config['room_srv']['port']; $listen_fd = socket_create(AF_INET, SOCK_STREAM, SOL_TCP); if(!socket_set_option($listen_fd, SOL_SOCKET, SO_REUSEADDR, 1)) { echo "socket_set_option 地址重用失败.\n"; } if(!socket_set_nonblock($listen_fd)) { $err = socket_last_error(); Log::record("socket_set_blocking error : {$err}",Log::DEBUG); } if(!socket_bind($listen_fd, $host, $port)) { echo "无法创建socket,请退出之前进程.\n"; return; } if(!socket_listen($listen_fd)) { echo "无法创建socket,请退出之前进程.\n"; return; } $count = 1; while ($count-- > 0) { fork_subprocess($count,$listen_fd); } //search_work($sockfd);