1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798 |
- <?php
- declare(strict_types=0);
- define('APP_ID','search');
- define('BASE_ROOT_PATH',str_replace('\\','/',dirname(__FILE__)));
- define('BASE_PATH', BASE_ROOT_PATH . '/helper');
- require_once(BASE_ROOT_PATH . '/global.php');
- require_once(BASE_ROOT_PATH . '/fooder.php');
- require_once(BASE_HELPER_PATH . '/event_looper.php');
- require_once(BASE_HELPER_PATH . '/search/processor.php');
- require_once(BASE_HELPER_PATH . '/search/util.php');
- require_once(BASE_HELPER_PATH . '/category_helper.php');
- require_once(BASE_HELPER_PATH . '/brand_helper.php');
- require_once(BASE_HELPER_PATH . '/goods/commonid_helper.php');
- require_once(BASE_HELPER_PATH . '/search/searcher.php');
- require_once(BASE_HELPER_PATH . '/special_helper.php');
- require_once(BASE_HELPER_PATH . '/search/area_library.php');
- require_once(BASE_HELPER_PATH . '/brand_helper.php');
- require_once(BASE_HELPER_PATH . '/algorithm.php');
- require_once(BASE_HELPER_PATH . '/message/msgstates.php');
- require_once(BASE_HELPER_PATH . '/message/msgutil.php');
- require_once(BASE_HELPER_PATH . '/message/subscriber.php');
- function handle_error($level, $message, $file, $line)
- {
- if($level == E_NOTICE) return;
- $trace = "handle_error: level={$level},msg={$message} file={$file},line={$line}\n";
- $backtrace = debug_backtrace();
- foreach ($backtrace as $item) {
- $trace .= "{$item['file']}\t{$item['line']}\t{$item['function']}\n";
- }
- Log::record($trace,Log::ERR);
- }
- set_error_handler('handle_error');
- function all_channels() {
- return ['searcher'];
- }
- $gMessageStates = null;
- function searchwork($sockfd)
- {
- $pid = posix_getpid();
- Log::record("seracher worker child process {$pid} is starting....",Log::DEBUG);
- try
- {
- global $gMessageStates;
- $gMessageStates = new MsgStates();
- Base::run_util();
- StatesHelper::init();
- $listener = new message\subscriber($gMessageStates);
- $listener->start();
- search\area_library::instance();
- if(StatesHelper::fetch_state('init')) {
- Log::record("StatesHelper::fetch_state first.",Log::DEBUG);
- search\searcher::instance()->init();
- }
- process_looper::instance()->init(new search\processor());
- process_looper::instance()->add_listen($sockfd);
- process_looper::instance()->run_loop();
- }
- catch (Exception $ex)
- {
- Log::record("Exception {$ex->getMessage()}",Log::ERR);
- }
- Log::record("child {$pid} searchwork quit",Log::DEBUG);
- exit(0);
- }
- global $config;
- $host = '0.0.0.0';
- $port = $config['searcher']['port'];
- $listen_fd = event\util::listen($host,$port);
- if($listen_fd === false) {
- Log::record("cannot open listen socket = {$host}:{$port}",Log::DEBUG);
- return false;
- }
- $count = 1;
- event\util::fork_listenex($listen_fd,'searchwork',$count);
- socket_close($listen_fd);
- Log::record("searchwork all child process quit.");
|