Пример #1
0
 /**
  * 检查worker配置、worker语法错误等
  * @return void
  */
 public static function checkWorkersConfig()
 {
     $current_pwuid = posix_getpwuid(posix_getuid());
     $current_user_name = $current_pwuid['name'];
     self::$maxUserNameLength = strlen($current_user_name);
     foreach (Config::getAllWorkers() as $worker_name => $config) {
         if (strlen($worker_name) > self::$maxWorkerNameLength) {
             self::$maxWorkerNameLength = strlen($worker_name);
         }
         if (isset($config['user']) && strlen($config['user']) > self::$maxUserNameLength) {
             self::$maxUserNameLength = strlen($config['user']);
         }
         if (isset($config['listen']) && strlen($config['listen']) > self::$maxListenLength) {
             self::$maxListenLength = strlen($config['listen']);
         }
     }
     $total_worker_count = 0;
     // 检查worker 是否有语法错误
     echo "------------------------ WORKERS -------------------------------\n";
     echo "user", str_pad('', self::$maxUserNameLength + 2 - strlen('user')), "worker", str_pad('', self::$maxWorkerNameLength + 2 - strlen('worker')), "listen", str_pad('', self::$maxListenLength + 2 - strlen('listen')), "processes", str_pad('', self::$maxProcessCountLength + 2 - strlen('processes')), "", "status\n";
     foreach (Config::getAllWorkers() as $worker_name => $config) {
         if (isset($config['user'])) {
             $worker_user = $config['user'];
             if (!self::checkWorkerUserName($worker_user)) {
                 echo str_pad($config['user'], self::$maxUserNameLength + 2), str_pad($worker_name, self::$maxWorkerNameLength + 2), " [FAIL] \n";
                 \Man\Core\Master::notice("Can not run {$worker_name} processes as user {$worker_user} , User {$worker_user} not exists\tWorkerman start fail");
                 exit("\nCan not run {$worker_name} processes as user {$worker_user} , User {$worker_user} not exists\n\nWorkerman start fail\n\n");
             }
         } else {
             $worker_user = $current_user_name;
         }
         echo str_pad($worker_user, self::$maxUserNameLength + 2), str_pad($worker_name, self::$maxWorkerNameLength + 2);
         if (isset($config['listen'])) {
             echo str_pad($config['listen'], self::$maxListenLength + 2);
         } else {
             echo str_pad('none', self::$maxListenLength + 2);
         }
         if (empty($config['start_workers'])) {
             \Man\Core\Master::notice(str_pad($worker_name, 40) . " [start_workers not set]\tWorkerman start fail");
             exit(str_pad('', self::$maxProcessCountLength + 2) . " [start_workers not set]\n\nWorkerman start fail\n");
         }
         echo str_pad(' ' . $config['start_workers'], self::$maxProcessCountLength + 2);
         $total_worker_count += $config['start_workers'];
         // 语法检查
         if ($worker_file = \Man\Core\Lib\Config::get($worker_name . '.worker_file')) {
             $class_name = basename($worker_file, '.php');
         } else {
             \Man\Core\Master::notice("{$worker_name} not set worker_file in conf/conf.d/{$worker_name}.conf");
             echo " [not set worker_file] \n";
             continue;
         }
         if (0 != self::checkSyntaxError($worker_file, $class_name)) {
             //unset(Config::instance()->config[$worker_name]);
             \Man\Core\Master::notice("{$worker_name} has Fatal Err");
             echo " [Fatal Err] \n";
             continue;
         }
         echo " [OK] \n";
     }
     if ($total_worker_count > \Man\Core\Master::SERVER_MAX_WORKER_COUNT) {
         \Man\Core\Master::notice("Number of worker processes can not be greater than " . \Man\Core\Master::SERVER_MAX_WORKER_COUNT . ".\tPlease check start_workers in " . WORKERMAN_ROOT_DIR . "config/main.php\tWorkerman start fail");
         exit("\nNumber of worker processes can not be greater than " . \Man\Core\Master::SERVER_MAX_WORKER_COUNT . ".\nPlease check start_workers in " . WORKERMAN_ROOT_DIR . "config/main.php\n\nWorkerman start fail\n");
     }
     echo "----------------------------------------------------------------\n";
 }
Пример #2
0
 /**
  * 检查worker配置、worker语法错误等
  * @return void
  */
 public static function checkWorkersConfig()
 {
     foreach (Config::getAllWorkers() as $worker_name => $config) {
         if (strlen($worker_name) > self::$maxWorkerNameLength) {
             self::$maxWorkerNameLength = strlen($worker_name);
         }
         if (isset($config['user']) && strlen($config['user']) > self::$maxUserNameLength) {
             self::$maxUserNameLength = strlen($config['user']);
         }
         if (isset($config['listen']) && strlen($config['listen']) > self::$maxListenLength) {
             self::$maxListenLength = strlen($config['listen']);
         }
     }
     $total_worker_count = 0;
     // 检查worker
     echo "------------------------ WORKERS -------------------------------\n";
     echo "worker", str_pad('', self::$maxWorkerNameLength + 2 - strlen('worker')), "listen", str_pad('', self::$maxListenLength + 2 - strlen('listen')), "processes", str_pad('', self::$maxProcessCountLength + 2 - strlen('processes')), "", "status\n";
     foreach (Config::getAllWorkers() as $worker_name => $config) {
         echo str_pad($worker_name, self::$maxWorkerNameLength + 2);
         if (isset($config['listen'])) {
             echo str_pad($config['listen'], self::$maxListenLength + 2);
         } else {
             echo str_pad('none', self::$maxListenLength + 2);
         }
         if (empty($config['start_workers'])) {
             \Man\Core\Master::notice(str_pad($worker_name, 40) . " [start_workers not set]\tWorkerman start fail");
             exit(str_pad('', self::$maxProcessCountLength + 2) . " [start_workers not set]\n\nWorkerman start fail\n");
         }
         echo str_pad(' ' . $config['start_workers'], self::$maxProcessCountLength + 2);
         $total_worker_count += $config['start_workers'];
         // 语法检查
         if (!($worker_file = \Man\Core\Lib\Config::get($worker_name . '.worker_file'))) {
             \Man\Core\Master::notice("{$worker_name} not set worker_file in conf/conf.d/{$worker_name}.conf");
             echo " [not set worker_file] \n";
             continue;
         }
         echo " [OK] \n";
     }
     if ($total_worker_count > \Man\Core\Master::SERVER_MAX_WORKER_COUNT) {
         \Man\Core\Master::notice("Number of worker processes can not be greater than " . \Man\Core\Master::SERVER_MAX_WORKER_COUNT . ".\tPlease check start_workers in " . WORKERMAN_ROOT_DIR . "config/main.php\tWorkerman start fail");
         exit("\nNumber of worker processes can not be greater than " . \Man\Core\Master::SERVER_MAX_WORKER_COUNT . ".\nPlease check start_workers in " . WORKERMAN_ROOT_DIR . "config/main.php\n\nWorkerman start fail\n");
     }
     echo "----------------------------------------------------------------\n";
 }