start_time = $start_time; $this->max_time = $max_time; $this->max_memory = $max_memory; $this->memory_threshold = $memory_threshold; } /** Returns false when the request should yield due to time or memory pressure. */ public function has_remaining(): bool { if (microtime(true) - $this->start_time >= $this->max_time) { return false; } $memory_used = memory_get_usage(true); if ($memory_used >= $this->max_memory * $this->memory_threshold) { return false; } return true; } }