예제 #1
0
 /**
  * 初始化环境
  *
  */
 private static function initEvn()
 {
     if (!self::$pidFile) {
         self::$pidFile = Cml::getApplicationDir('global_store_path') . DIRECTORY_SEPARATOR . 'DaemonProcess_.pid';
         self::$log = Cml::getApplicationDir('global_store_path') . DIRECTORY_SEPARATOR . 'DaemonProcess_.log';
         self::$status = Cml::getApplicationDir('global_store_path') . DIRECTORY_SEPARATOR . 'DaemonProcessStatus.php';
         self::checkExtension();
     }
 }
예제 #2
0
 /**
  * shell参数处理并启动守护进程
  *
  * @param string $cmd
  */
 public static function run($cmd)
 {
     self::$pidFile = Cml::getApplicationDir('global_store_path') . DIRECTORY_SEPARATOR . 'DaemonProcess_.pid';
     self::$log = Cml::getApplicationDir('global_store_path') . DIRECTORY_SEPARATOR . 'DaemonProcess_.log';
     self::$status = Cml::getApplicationDir('global_store_path') . DIRECTORY_SEPARATOR . 'DaemonProcessStatus.php';
     self::checkExtension();
     $param = is_array($cmd) && count($cmd) == 2 ? $cmd[1] : $cmd;
     switch ($param) {
         case 'start':
             self::start();
             break;
         case 'stop':
             posix_kill(self::getPid(), SIGINT);
             self::message('stop....');
             break;
         case 'reload':
             posix_kill(self::getPid(), SIGUSR1);
             self::message('reloading....');
             break;
         case 'status':
             self::getStatus(true);
             break;
         case 'addtask':
             if (func_num_args() < 1) {
                 self::message('please input task name');
                 break;
             }
             $args = func_get_args();
             $frequency = isset($args[2]) ? intval($args[2]) : 60;
             $frequency < 1 || ($frequency = 60);
             self::addTask($args[1], $frequency);
             break;
         case 'rmtask':
             if (func_num_args() < 1) {
                 self::message('please input task name');
                 break;
             }
             $args = func_get_args();
             self::rmTask($args[1]);
             break;
         default:
             self::message('Usage: xxx.php cml.cmd DaemonWorker::run {start|stop|status|addtask|rmtask}');
             break;
     }
 }