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()); echo "start ending"; search\CentraHelper::instance()->run_loop($sockfd); echo "end run_loop"; } function fork_subprocess($count,$listen_fd) { if (($child = 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. echo "pid = {$child} count = {$count} " . __LINE__ ."\r\n"; search_work($listen_fd); exit(); } elseif($child === -1) { echo "pid = {$child} count = {$count} " . __LINE__ ."\r\n"; die('could not fork'); } else { echo "pid = {$child} count = {$count} " . __LINE__ ."\r\n"; $ret = pcntl_waitpid($child,$status,WNOHANG); if($ret == 0) { echo "spawn-fcgi: successful ret == 0 PID: {$child}\n" ; } elseif($ret == -1) { echo "spawn-fcgi: ret == 0 PID: {$child}\n" ; } else { echo "spawn-fcgi: ret == 0 child exited PID: {$child}.\n"; } } } 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) { $count = 1; while ($count-- > 0) { fork_subprocess($count,$listen_fd); } } else { echo "无法创建socket,请退出之前进程.\n"; }