/** * Checks if there is enough memory and time left on the Server. * * @return bool * Boolean to show if we have enough left. * TRUE = all is OK. * FALSE = we have a problem. */ public function checkEmergencyBreak() { if (!$this->enabled) { // Tell them, everything is OK! return true; } if (self::$allIsOk === false) { // This has failed before! // No need to check again! return false; } // Check Runtime. if ($this->timer + $this->maxRuntime <= time()) { // This is taking longer than expected. $this->storage->messages->addMessage('Emergency break due to extensive run time!'); \Krexx::editSettings(); \Krexx::disable(); self::$allIsOk = false; return false; } // Still here ? Commence with the memory check. // We will only check, if we were able to determine a memory limit // in the first place. if ($this->serverMemoryLimit > 2) { $usage = memory_get_usage(); $left = $this->serverMemoryLimit - $usage; // Is more left than is configured? if ($left < $this->minMemoryLeft * 1024 * 1024) { $this->storage->messages->addMessage('Emergency break due to extensive memory usage!'); // Show settings to give the dev to repair the situation. \Krexx::editSettings(); \Krexx::disable(); self::$allIsOk = false; return false; } } // Still here? Everything must be good :-) return true; }