当前位置: 首页>>代码示例>>PHP>>正文


PHP Daemon::process方法代码示例

本文整理汇总了PHP中Daemon::process方法的典型用法代码示例。如果您正苦于以下问题:PHP Daemon::process方法的具体用法?PHP Daemon::process怎么用?PHP Daemon::process使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Daemon的用法示例。


在下文中一共展示了Daemon::process方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: run

 /**
  * Runtime of Master process
  * @return void
  */
 public function run()
 {
     Daemon::$process = $this;
     $this->prepareSystemEnv();
     class_exists('Timer');
     // ensure loading this class
     gc_enable();
     $this->eventBase = event_base_new();
     $this->registerEventSignals();
     FS::initEvent();
     $this->fileWatcher = new FileWatcher();
     $this->workers = new ThreadCollection();
     $this->collections['workers'] = $this->workers;
     Daemon::$appResolver = (require Daemon::$config->path->value);
     $this->IPCManager = Daemon::$appResolver->getInstanceByAppName('IPCManager');
     Daemon::$appResolver->preload(true);
     $this->callbacks = new SplStack();
     $this->spawnWorkers(min(Daemon::$config->startworkers->value, Daemon::$config->maxworkers->value));
     Timer::add(function ($event) use(&$cbs) {
         $self = Daemon::$process;
         static $c = 0;
         ++$c;
         if ($c > 0xfffff) {
             $c = 1;
         }
         if ($c % 10 == 0) {
             $self->workers->removeTerminated(true);
             gc_collect_cycles();
         } else {
             $self->workers->removeTerminated();
         }
         if (isset(Daemon::$config->mpm->value) && is_callable(Daemon::$config->mpm->value)) {
             call_user_func(Daemon::$config->mpm->value);
         } else {
             // default MPM
             $state = Daemon::getStateOfWorkers($self);
             if ($state) {
                 $n = max(min(Daemon::$config->minspareworkers->value - $state['idle'], Daemon::$config->maxworkers->value - $state['alive']), Daemon::$config->minworkers->value - $state['alive']);
                 if ($n > 0) {
                     Daemon::log('Spawning ' . $n . ' worker(s).');
                     $self->spawnWorkers($n);
                     event_base_loopbreak($self->eventBase);
                 }
                 $n = min($state['idle'] - Daemon::$config->maxspareworkers->value, $state['alive'] - Daemon::$config->minworkers->value);
                 if ($n > 0) {
                     Daemon::log('Stopping ' . $n . ' worker(s).');
                     $self->stopWorkers($n);
                 }
             }
         }
         $event->timeout();
     }, 1000000.0 * Daemon::$config->mpmdelay->value, 'MPM');
     while (!$this->breakMainLoop) {
         while (!$this->callbacks->isEmpty()) {
             call_user_func($this->callbacks->shift(), $this);
         }
         event_base_loop($this->eventBase);
     }
 }
开发者ID:ruslanchek,项目名称:phpdaemon,代码行数:63,代码来源:Daemon_MasterThread.php

示例2: run

 /**
  * Runtime of Worker process.
  * @return void
  */
 protected function run()
 {
     Daemon::$process = $this;
     $this->autoReloadLast = time();
     $this->reloadDelay = Daemon::$config->mpmdelay->value + 2;
     $this->setStatus(4);
     if (Daemon::$config->autogc->value > 0) {
         gc_enable();
     } else {
         gc_disable();
     }
     $this->prepareSystemEnv();
     $this->overrideNativeFuncs();
     $this->setStatus(6);
     $this->eventBase = event_base_new();
     $this->registerEventSignals();
     $this->fileWatcher = new FileWatcher();
     $this->IPCManager = Daemon::$appResolver->getInstanceByAppName('IPCManager');
     Daemon::$appResolver->preload();
     foreach (Daemon::$appInstances as $app) {
         foreach ($app as $appInstance) {
             if (!$appInstance->ready) {
                 $appInstance->ready = TRUE;
                 $appInstance->onReady();
             }
         }
     }
     $this->setStatus(1);
     /**
      * @closure readPoolEvent
      * @description Invokes the AppInstance->readConn() method for every updated connection in pool. readConn() reads new data from the buffer.
      * @return void
      */
     $this->readPoolEvent = Daemon_TimedEvent::add(function ($event) {
         $self = Daemon::$process;
         foreach ($self->readPoolState as $connId => $state) {
             if (Daemon::$config->logevents->value) {
                 $self->log('event readConn(' . $connId . ') invoked.');
             }
             $self->poolApp[$connId]->readConn($connId);
             if (Daemon::$config->logevents->value) {
                 $self->log('event readConn(' . $connId . ') finished.');
             }
         }
         if (sizeof($self->readPoolState) > 0) {
             $event->timeout();
         }
     }, 1000000.0 * 0.005, 'readPoolEvent');
     Daemon_TimedEvent::add(function ($event) {
         $self = Daemon::$process;
         if ($self->checkState() !== TRUE) {
             $self->closeSockets();
             $self->breakMainLoop = TRUE;
             event_base_loopexit($self->eventBase);
             return;
         }
         $event->timeout();
     }, 1000000.0 * 1, 'checkStateTimedEvent');
     if (Daemon::$config->autoreload->value > 0) {
         Daemon_TimedEvent::add(function ($event) {
             $self = Daemon::$process;
             static $n = 0;
             $inc = array_unique(array_map('realpath', get_included_files()));
             $s = sizeof($inc);
             if ($s > $n) {
                 $slice = array_slice($inc, $n);
                 Daemon::$process->IPCManager->sendPacket(array('op' => 'addIncludedFiles', 'files' => $slice));
                 $n = $s;
             }
             $event->timeout();
         }, 1000000.0 * Daemon::$config->autoreload->value, 'watchIncludedFilesTimedEvent');
     }
     while (!$this->breakMainLoop) {
         event_base_loop($this->eventBase);
     }
 }
开发者ID:J3FF3,项目名称:phpdaemon,代码行数:80,代码来源:Daemon_WorkerThread.php

示例3: run

 /**
  * Runtime of Worker process.
  * @return void
  */
 public function run()
 {
     FS::init();
     Daemon::$process = $this;
     if (Daemon::$logpointerAsync) {
         $oldfd = Daemon::$logpointerAsync->fd;
         Daemon::$logpointerAsync->fd = null;
         Daemon::$logpointerAsync = null;
     }
     $this->autoReloadLast = time();
     $this->reloadDelay = Daemon::$config->mpmdelay->value + 2;
     $this->setStatus(4);
     if (Daemon::$config->autogc->value > 0) {
         gc_enable();
     } else {
         gc_disable();
     }
     $this->prepareSystemEnv();
     $this->overrideNativeFuncs();
     $this->setStatus(6);
     $this->eventBase = event_base_new();
     $this->registerEventSignals();
     FS::init();
     // re-init
     FS::initEvent();
     Daemon::openLogs();
     $this->fileWatcher = new FileWatcher();
     $this->IPCManager = Daemon::$appResolver->getInstanceByAppName('IPCManager');
     Daemon::$appResolver->preload();
     foreach (Daemon::$appInstances as $app) {
         foreach ($app as $appInstance) {
             if (!$appInstance->ready) {
                 $appInstance->ready = TRUE;
                 $appInstance->onReady();
             }
         }
     }
     $this->setStatus(1);
     Timer::add(function ($event) {
         $self = Daemon::$process;
         if ($self->checkState() !== TRUE) {
             $self->closeSockets();
             $self->breakMainLoop = TRUE;
             event_base_loopexit($self->eventBase);
             return;
         }
         $event->timeout();
     }, 1000000.0 * 1, 'checkState');
     if (Daemon::$config->autoreload->value > 0) {
         Timer::add(function ($event) {
             $self = Daemon::$process;
             static $n = 0;
             $inc = array_unique(array_map('realpath', get_included_files()));
             $s = sizeof($inc);
             if ($s > $n) {
                 $slice = array_slice($inc, $n);
                 Daemon::$process->IPCManager->sendPacket(array('op' => 'addIncludedFiles', 'files' => $slice));
                 $n = $s;
             }
             $event->timeout();
         }, 1000000.0 * Daemon::$config->autoreload->value, 'watchIncludedFiles');
     }
     while (!$this->breakMainLoop) {
         event_base_loop($this->eventBase);
     }
 }
开发者ID:ruslanchek,项目名称:phpdaemon,代码行数:70,代码来源:Daemon_WorkerThread.php


注:本文中的Daemon::process方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。