123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115 |
- <?php
- define('BASE_ROOT_PATH',str_replace('\\','/',dirname(__FILE__)));
- require_once (BASE_ROOT_PATH . '/fooder.php');
- require_once (BASE_ROOT_PATH . '/helper/search/server.php');
- require_once (BASE_ROOT_PATH . '/helper/search/processor.php');
- require_once (BASE_ROOT_PATH . '/helper/search/event_handler.php');
- require_once(BASE_ROOT_PATH . '/helper/search/util.php');
- require_once(BASE_ROOT_PATH . '/helper/category_helper.php');
- require_once(BASE_ROOT_PATH . '/helper/brand_helper.php');
- require_once(BASE_ROOT_PATH . '/helper/search/searcher.php');
- require_once(BASE_ROOT_PATH . '/helper/search/area_library.php');
- require_once(BASE_ROOT_PATH . '/helper/brand_helper.php');
- require_once(BASE_ROOT_PATH . '/helper/algorithm.php');
- require_once (BASE_ROOT_PATH . '/helper/message/msgutil.php');
- require_once (BASE_ROOT_PATH . '/helper/message/subscriber.php');
- function all_channels()
- {
- return array('searcher');
- }
- $gMessageStates = null;
- $gMessageLock = null;
- function search_work($sockfd)
- {
- global $gMessageStates;
- global $gMessageLock;
- $gMessageStates = new MsgStates();
- $gMessageLock = Mutex::create();
- echo "start searcher";
- Base::run_util();
- StatesHelper::init();
- $listener = new message\subscriber($gMessageStates,$gMessageLock);
- $listener->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";
- }
|