/** * Get state of workers. * @return array - information. */ public static function getStateOfWorkers() { $offset = 0; $stat = ['idle' => 0, 'busy' => 0, 'alive' => 0, 'shutdown' => 0, 'preinit' => 0, 'init' => 0, 'reloading' => 0]; $readed = 0; $readedStr = ''; while (($buf = Daemon::$shm_wstate->read($readed, 1024)) !== false) { $readed += strlen($buf); $readedStr .= $buf; for ($i = 0, $buflen = strlen($buf); $i < $buflen; ++$i) { $code = ord($buf[$i]); if ($code >= 100) { // reloaded (shutdown) $code -= 100; if ($code !== Daemon::WSTATE_SHUTDOWN) { ++$stat['alive']; if (Daemon::$process instanceof Thread\Master) { Daemon::$process->reloadWorker($offset + $i + 1); ++$stat['reloading']; continue; } } } if ($code === Daemon::WSTATE_IDLE) { // idle ++$stat['alive']; ++$stat['idle']; } elseif ($code === Daemon::WSTATE_BUSY) { // busy ++$stat['alive']; ++$stat['busy']; } elseif ($code === Daemon::WSTATE_SHUTDOWN) { // shutdown ++$stat['shutdown']; } elseif ($code === Daemon::WSTATE_PREINIT) { // pre-init ++$stat['alive']; ++$stat['preinit']; ++$stat['idle']; } elseif ($code === Daemon::WSTATE_INIT) { // init ++$stat['alive']; ++$stat['init']; ++$stat['idle']; } } } //Daemon::log('readedStr: '.Debug::exportBytes($readedStr, true)); return $stat; }