raiseMemoryLimit(); $photo = Photo::query()->with('device')->find($this->photoId); if ($photo === null) { return; } $scan->scanPhoto($photo); } private function raiseMemoryLimit(): void { $raw = strtolower(trim((string) ini_get('memory_limit'))); if ($raw === '' || $raw === '-1') { return; } $n = (int) $raw; $bytes = match (substr($raw, -1)) { 'g' => $n * 1024 * 1024 * 1024, 'm' => $n * 1024 * 1024, 'k' => $n * 1024, default => (int) $raw, }; if ($bytes > 0 && $bytes < 256 * 1024 * 1024) { ini_set('memory_limit', '256M'); } } }