start(); if(StatesHelper::fetch_state('init')) { Log::record("StatesHelper::fetch_state first.",Log::DEBUG); search\searcher::instance()->init(); search\area_library::instance(); } search\CentraHelper::instance()->init(new search\processor()); search\CentraHelper::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); } } } function remote_addr() { global $config; $host = $config['searcher']['host']; $port = $config['searcher']['port']; return "{$host}:{$port}"; } $listen_fd = stream_socket_server (remote_addr(), $errno, $errstr); if($listen_fd == false) { echo "无法创建socket,请退出之前进程.\n"; } $count = 1; while ($count-- > 0) { fork_subprocess($count,$listen_fd); }