public function next() { sem_acquire($this->sem()); try { $meta = $this->shm->get(0); $meta["pos"]++; $ret = $meta["keys"][$meta["pos"]]; $this->shm->put(0, $meta); sem_release($this->sem()); return $ret; } catch (Exception $e) { sem_release($this->sem()); throw $e; } return next($this->container); }
protected function handleChildEvents($nmess = null) { $i = 0; while ($message = $this->childEventQueue->peek()) { $t1 = microtime(true); $this->logger->debug(sprintf("Peeked '%s' from event queue", $message["type"])); switch ($message["type"]) { case "beforeHandleWork": $this->childs[$message["pid"]]["workStartTime"] = $message["microtime"]; $this->childs[$message["pid"]]["message"] = $message["message"]; break; case "afterHandleWork": unset($this->childs[$message["pid"]]["workStartTime"]); unset($this->childs[$message["pid"]]["message"]); break; case "start": if (!$this->ready) { $this->shm->put(self::SHM_STARTUP_BARRIER, $this->shm->get(self::SHM_STARTUP_BARRIER) + 1); } else { $this->childs[$message["pid"]]["startTime"] = microtime(true); } break; case "memoryUsage": if ($this->workerMemoryLimit && $message["memory"] > $this->workerMemoryLimit) { $this->logger->info(sprintf("Worker %d allocates %d Kb. Maximum %d Kb is allowed by configuration", $message["pid"], $message["memory"], $this->workerMemoryLimit)); $this->terminateChild($message["pid"]); } break; default: $this->logger->warn("Peeked unknown message from child event queue. " . "Serialized message: {$message}"); } $this->logger->info("Child message handle: " . round(microtime(true) - $t1, 4) . " sec"); $i++; if ($nmess && $i >= $nmess) { break; } } }
private function putMeta($meta) { $this->logger->debug("put meta (size: {$meta["size"]}, nextIndex: {$meta["nextIndex"]})"); $this->shm->put(0, $meta); }
function onReady($pool) { $this->logger->info("[IPC] Store process pool (pid: {$this->processPool->getPid()}) in shm"); $this->shm->put(0, $this->processPool->getPid()); $this->logger->info("[IPC] Process pool PID check: " . $this->shm->get(0)); }
function onReady($pool) { $this->logger->debug("Store process pool (pid: {$this->processPool->getPid()}) in shm"); $this->shm->put(0, $this->processPool->getPid()); }