/** * @return ForkManager */ public function create() { $event = new ForkManagerEvent(); $eventDispatcher = new EventDispatcher(); $memoryLimitManager = new MemoryLimitManager(); $taskManager = new TaskManager(); $timeLimitManager = new TimeLimitManager(); //set default values for optional properties $memoryLimitManager->setLimitInMegaBytes(128); $memoryLimitManager->setBufferInMegaBytes(8); $timeLimitManager->setLimitInHours(1); $timeLimitManager->setBufferInMinutes(4); $manager = new ForkManager(); $manager->injectEvent($event); $manager->injectEventDispatcher($eventDispatcher); $manager->injectMemoryLimitManager($memoryLimitManager); $manager->injectTimeLimitManager($timeLimitManager); $manager->injectTaskManager($taskManager); $manager->setMaximumNumberOfThreads(16); $manager->setNumberOfMicrosecondsToCheckThreadStatus(100000); //1000000 microseconds = 1 second return $manager; }
/** * @return bool */ private function isMaximumMemoryLimitOfWholeThreadsReached() { $processIds = array_keys($this->threads); $isReached = $this->memoryLimitManager->isLimitReached($processIds); return $isReached; }