protected function initMonitor()
 {
     Application::RegisterClass(\DIServer\Monitor\SwooleTable::class);
     Application::RegisterInterfaceByClass(\DIServer\Interfaces\IMonitor::class, \DIServer\Monitor\SwooleTable::class);
     $monitor = Application::GetInstance(\DIServer\Interfaces\IMonitor::class);
     $monitor->Bind();
 }
Example #2
0
 /**
  * 进程启动时被触发
  *
  * @param \swoole_server $server    当前进程的swoole_server对象
  * @param int            $worker_id 当前进程的ID
  */
 public function OnWorkerStart(\swoole_server $server, $worker_id)
 {
     Log::Notice("On Worker[{$worker_id}] Start.");
     $workerStrapps = (include Application::GetFrameworkPath() . '/Registry/Worker.php');
     Application::AutoRegistry($workerStrapps);
     Event::Listen('OnWorkerStart', [&$server, &$worker_id]);
 }
Example #3
0
 protected function settingCheck(&$setting)
 {
     //有一些配置是DIServer运行必须控制的。
     if ($setting['task_worker_num'] <= 0) {
         throw new BootException("Error: 配置swoole.task_worker_num被设置为0。");
     }
     if ($setting['task_ipc_mode'] != 2) {
         throw new BootException("Error: 配置swoole.task_ipc_mode设置不是2。");
     }
     if ($setting['dispatch_mode'] == 1 || $setting['dispatch_mode'] == 3) {
         throw new BootException("Error: 配置swoole.dispatch_mode=1/3时,底层会屏蔽onConnect/onClose事件,原因是这2种模式下无法保证onConnect/onClose/onReceive的顺序。");
     }
     if (isset($setting['chroot'])) {
         throw new BootException("Error: 配置swoole.chroot会导致autoloader无法在工作\\任务进程正常使用,请确定你能处理(如修改autoloader的路径)然后过来注释这个异常。");
     }
     if (!isset($setting['package_eof'])) {
         $setting['package_eof'] = '';
         //疑似swoole bug,如果不显式指定package_eof则无法正常收包。
     }
     if (!isset($setting['task_tmpdir'])) {
         $setting['task_tmpdir'] = Application::GetServerPath('/Runtimes/TaskTemp');
     }
     if (!isset($setting['log_file'])) {
         $setting['log_file'] = Application::GetServerPath('/Runtimes/Log/' . Application::GetServerName() . '.log');
     }
     if (!isset($setting['message_queue_key'])) {
         $setting['message_queue_key'] = ftok(Application::GetServerPath(), 0);
     }
     $setting['daemonize'] = DI_DAEMONIZE;
 }
Example #4
0
 /**
  * 在第一次调用时动态加载配置文件
  *
  * @param $pk
  */
 protected function autoLoad($pk, $ext = '.php')
 {
     $files = Application::GetConventionPaths("/Config/{$pk}{$ext}");
     foreach ($files as $file) {
         $this->loadFromArray($file, $ext);
     }
 }
 protected function loadService($servicesConfig = [])
 {
     foreach ($servicesConfig as $iface => $imp) {
         Application::RegisterClass($imp);
         if (Application::IsAbstract($iface)) {
             Application::RegisterInterfaceByClass($iface, $imp);
         }
     }
 }
Example #6
0
 public function Bootstrap()
 {
     $processes = Application::AutoBuildCollection('Process.php', \swoole_process::class);
     foreach ($processes as $processClass => $process) {
         if (Server::AddProcess($process)) {
             Log::Notice("User process {processClass} has added.", ['processClass' => get_class($process)]);
         }
     }
 }
 /**
  * 进程启动时被触发
  *
  * @param \swoole_server $server    当前进程的swoole_server对象
  * @param int            $worker_id 当前进程的ID
  */
 public function OnTaskWorkerStart(\swoole_server $server, $task_worker_id)
 {
     Log::Notice("On Task Worker[{$task_worker_id}] Start.");
     if (file_exists(Application::GetServerPath() . '/Registry/TaskWorker.php')) {
         $registry = (include Application::GetServerPath() . '/Registry/TaskWorker.php');
         Application::AutoRegistry($registry);
     }
     Event::Listen('OnTaskWorkerStart', [&$server, &$task_worker_id]);
 }
Example #8
0
 protected function bootWithBootstraps(array $bootstraps = [])
 {
     foreach ($bootstraps as $boot) {
         /* @var $bootstrap \DIServer\Bootstraps\Bootstrap */
         $bootstrap = Application::BuildWithClass($boot);
         $bootstrap->BeforeBootstrap();
         $bootstrap->Bootstrap();
         $bootstrap->AfterBootstrap();
     }
 }
Example #9
0
 public function __construct()
 {
     $handlers = Application::AutoBuildCollection('Handler.php');
     foreach ($handlers as $key => $handler) {
         if (is_array($handler)) {
             $this->handlers[$key] = $this->_createPipeClosure($handler);
         } else {
             $this->handlers[$key] = [$this->_createPipeClosure($handler)];
         }
     }
 }
Example #10
0
 private function _tryRegitryHandler($handlerID, $handlerClassName)
 {
     if (class_exists($handlerClassName)) {
         $handlerRefClass = new \ReflectionClass($handlerClassName);
         if ($handlerRefClass->isSubclassOf(IHandler::class)) {
             Application::RegisterClass($handlerClassName);
             Application::RegisterInterfaceByClass(IHandler::class, $handlerRefClass->getName(), $handlerRefClass->getName());
             $handlerObj = Application::GetInstance(IHandler::class, $handlerRefClass->getName());
             $this->handlers[$handlerID][] = $handlerObj;
         } else {
             Log::Warning("Load {$handlerClassName} is not instance of IHandler.");
         }
     } else {
         Log::Warning("Try to load {$handlerClassName} but not exist.");
     }
 }
Example #11
0
 public function __construct()
 {
     $this->path = Application::GetServerPath('/Runtimes/Session');
     // 锁定
     $lockfile = $this->path . 'build.Runtimes.lock';
     if (is_writable($lockfile)) {
         return;
     } else {
         if (!touch($lockfile)) {
             throw new \Exception('应用目录[' . $this->path . ']不可写,目录无法自动生成!请手动生成项目目录~', 10006);
         }
     }
     if (!is_dir($this->path)) {
         //echo "mkdir($this->path, 0755, true);\n";
         mkdir($this->path, 0755, true);
     }
     // 解除锁定
     unlink($lockfile);
 }
Example #12
0
 protected function initProxy()
 {
     /** @var \DIServer\Interfaces\Swoole\ISwooleProxy $swooleProxy */
     Application::GetInstance(ISwooleProxy::class);
 }
Example #13
0
 /**
  * Worker进程启动时触发并划分普通worker进程和task进程
  *
  * @param \swoole_server $server
  * @param int            $worker_id
  *
  * @throws \DIServer\Container\NotRegistedException
  * @throws \DIServer\Container\NotTypeOfInstanceException
  */
 public function OnWorkerStart(\swoole_server $server, $worker_id)
 {
     //清理opcache
     opcache_reset();
     //各个进程的$server对象不是同一个,要重置。
     Container::Unregister(\swoole_server::class);
     Container::RegisterClassByInstance(\swoole_server::class, $server);
     Application::AutoRegistry('CommonWorker.php', true);
     if ($server->taskworker) {
         $this->taskerServer = Container::GetInstance(ITaskWorkerServer::class);
         Application::AutoRegistry('TaskWorker.php', true);
         Event::Listen('OnTaskWorkerStart', [&$server, &$worker_id]);
         $this->taskerServer->OnTaskWorkerStart($server, $worker_id);
     } else {
         $this->workerServer = Container::GetInstance(IWorkerServer::class);
         Application::AutoRegistry('Worker.php', true);
         Event::Listen('OnWorkerStart', [&$server, &$worker_id]);
         $this->workerServer->OnWorkerStart($server, $worker_id);
     }
 }
Example #14
0
 /**
  * Worker进程启动时触发并划分普通worker进程和task进程
  *
  * @param \swoole_server $server
  * @param int            $worker_id
  *
  * @throws \DIServer\Container\NotRegistedException
  * @throws \DIServer\Container\NotTypeOfInstanceException
  */
 public function OnWorkerStart(\swoole_server $server, $worker_id)
 {
     //各个进程的$server对象不是同一个,要重置。
     Container::Unregister(\swoole_server::class);
     Container::RegisterClassByInstance(\swoole_server::class, $server);
     $reloadConfig = (include Application::GetFrameworkPath() . '/Registry/ServerReload.php');
     Container::AutoRegistry($reloadConfig);
     if ($server->taskworker) {
         $this->taskerServer = Container::GetInstance(ITaskWorkerServer::class);
         $this->taskerServer->OnTaskWorkerStart($server, $worker_id);
     } else {
         $this->workerServer = Container::GetInstance(IWorkerServer::class);
         $this->workerServer->OnWorkerStart($server, $worker_id);
     }
 }