/** * Runtime of Worker process. * @return void */ protected function run() { if (Daemon::$process instanceof Master) { Daemon::$process->unregisterSignals(); } EventLoop::init(); Daemon::$process = $this; if (Daemon::$logpointerAsync) { Daemon::$logpointerAsync->fd = null; Daemon::$logpointerAsync = null; } class_exists('Timer'); if (Daemon::$config->autogc->value > 0) { gc_enable(); } else { gc_disable(); } $this->prepareSystemEnv(); $this->registerEventSignals(); FileSystem::init(); // re-init FileSystem::initEvent(); Daemon::openLogs(); $this->fileWatcher = new FileWatcher(); $this->IPCManager = Daemon::$appResolver->getInstanceByAppName('\\PHPDaemon\\IPCManager\\IPCManager'); if (!$this->IPCManager) { $this->log('cannot instantiate IPCManager'); } EventLoop::$instance->run(); }
protected function prepareAsync() { EventLoop::init(); Daemon::initSettings(); FileSystem::init(); FileSystem::initEvent(); }
/** * Runtime of Worker process. * @return void */ protected function run() { $this->lambdaCache = new CappedStorageHits(); $this->lambdaCache->setMaxCacheSize(Daemon::$config->lambdacachemaxsize->value); $this->lambdaCache->setCapWindow(Daemon::$config->lambdacachecapwindow->value); if (Daemon::$process instanceof Master) { Daemon::$process->unregisterSignals(); } EventLoop::init(); Daemon::$process = $this; if (Daemon::$logpointerAsync) { Daemon::$logpointerAsync->fd = null; Daemon::$logpointerAsync = null; } class_exists('Timer'); $this->autoReloadLast = time(); $this->reloadDelay = Daemon::$config->mpmdelay->value + 2; $this->setState(Daemon::WSTATE_PREINIT); if (Daemon::$config->autogc->value > 0) { gc_enable(); gc_collect_cycles(); } else { gc_disable(); } if (Daemon::$runworkerMode) { if (!Daemon::$config->verbosetty->value) { fclose(STDIN); fclose(STDOUT); fclose(STDERR); } Daemon::$appResolver->preload(true); } $this->prepareSystemEnv(); $this->overrideNativeFuncs(); $this->setState(Daemon::WSTATE_INIT); $this->registerEventSignals(); FileSystem::init(); FileSystem::initEvent(); Daemon::openLogs(); $this->IPCManager = Daemon::$appResolver->getInstanceByAppName('\\PHPDaemon\\IPCManager\\IPCManager'); if (!$this->IPCManager) { $this->log('cannot instantiate IPCManager'); } Daemon::$appResolver->preload(); foreach (Daemon::$appInstances as $app) { foreach ($app as $appInstance) { if (!$appInstance->ready) { $appInstance->ready = true; $appInstance->onReady(); } } } $this->setState(Daemon::WSTATE_IDLE); Timer::add(function ($event) { if (!Daemon::$runworkerMode) { if ($this->IPCManager) { $this->IPCManager->ensureConnection(); } } $this->breakMainLoopCheck(); if (Daemon::checkAutoGC()) { EventLoop::$instance->interrupt(function () { gc_collect_cycles(); }); } $event->timeout(); }, 1000000.0 * 1, 'breakMainLoopCheck'); if (Daemon::$config->autoreload->value > 0) { Timer::add(function ($event) { static $n = 0; $list = get_included_files(); $s = sizeof($list); if ($s > $n) { $slice = array_map('realpath', array_slice($list, $n)); Daemon::$process->IPCManager->sendPacket(['op' => 'addIncludedFiles', 'files' => $slice]); $n = $s; } $event->timeout(); }, 1000000.0 * Daemon::$config->autoreload->value, 'watchIncludedFiles'); } EventLoop::$instance->run(); $this->shutdown(); }