} \ServerBench\Cli\show_status($pid); exit; } $listen_addr = $arguments->get('listen'); if (!isset($listen_addr)) { \ServerBench\Cli\printf_and_exit("argument --listen or -l should be set.\n"); } \ServerBench\syslog_info('listen %s', [$listen_addr]); $app_path = $arguments->get('app'); if (!isset($app_path)) { \ServerBench\Cli\printf_and_exit("arugment --app should be set.\n"); } $app_path = realpath($app_path); if (!file_exists($app_path)) { \ServerBench\Cli\printf_and_exit("app(%s) does not exist.\n", $app_path); } $ipcs = $arguments->get('ipcs'); if (!isset($ipcs)) { $rand = mt_rand(); $ipcs = sprintf('ipc://%s/ipc%d_%s_0.sock,ipc://%s/ipc%d_%s_1.sock', $dir, $rand, $title, $dir, $rand, $title); } \ServerBench\syslog_info('app %s', [$app_path]); $workers = $arguments->get('workers', 1); \ServerBench\syslog_info('start workers %d', [$workers]); if (isset($arguments['daemonize'])) { \ServerBench\syslog_info('run as daemon.'); ProcessUtil::daemon(); } $pid = getmypid(); \ServerBench\syslog_info('pid of controller is %d', [$pid]);
\ServerBench\Cli\printf_and_exit("please run @ cli.\n"); } $arguments = new CliArguments(array('l:' => 'listen:', 'd' => 'daemonize', 'D:' => 'dir:', 'T:' => 'title:', 'app:', 'ipcs:')); if (isset($arguments['dir'])) { chdir($arguments['dir']); } if (!isset($arguments['listen'])) { \ServerBench\Cli\printf_and_exit("argument --listen or -l should be set.\n"); } $listen_addr = explode(',', $arguments['listen']); if (!isset($arguments['ipcs'])) { \ServerBench\Cli\printf_and_exit("argument --ipcs should be set.\n"); } $ipcs = explode(',', $arguments['ipcs']); if (count($ipcs) != 2) { \ServerBench\Cli\printf_and_exit("argument --ipcs should be a couple of sock files.\n"); } $api = null; $app_path = $arguments->get('app'); ProcessUtil::setTitle($arguments->get('title', 'serverbench<proxy>')); try { if (isset($app_path) && file_exists($app_path)) { $api = new Api('proxy', include $app_path); } if ($api && false === $api->init()) { \ServerBench\syslog_error('app->init(\'proxy\') returns false.'); exit; } PeriodicGc::enable(300); $proxy = new Proxy($listen_addr, $ipcs); $proxy->run();