Error message
PHP: Allowed memory size of … bytes exhausted
A PHP script asked for more memory than memory_limit allows. PHP stops it with a fatal error, not an exception: no catch block runs. The Sentry SDK still reports it, because it keeps a little memory in reserve for exactly this case, but the event holds less than you would expect: a single frame, the line where memory ran out.
Examples run on 21 November 2026 with PHP 8.6.0, sentry/sentry 4.17.1, 4.27.0 and 4.38.0, and Laravel 13.43.0 with sentry/sentry-laravel 4.22.0, 4.26.0 and 4.31.0. Errilo is in private beta.
What the message says
A loop that keeps adding 1 MiB strings to an array, with a 32 MiB limit:
<?php
// oom.php, run with: php -d memory_limit=32M oom.php
function load(): array {
$rows = [];
while (true) { $rows[] = str_repeat('x', 1024 * 1024); } // line 7
}
load();PHP 8.6.0 prints the message, then the call stack:
Fatal error: Allowed memory size of 33554432 bytes exhausted (tried to allocate 2097152 bytes) in /app/oom.php on line 7
Stack trace:
#0 /app/oom.php(7): str_repeat('x', 1048576)
#1 {main}33554432 bytesis thememory_limitin force, here 32M. The default is128M, which is what PHP 8.6.0 reported without anyphp.iniand what our Laravel app ran with.tried to allocate 2097152 bytesis the allocation that failed, not the cause. The script was already close to the limit, and the line that fails is simply the one that asked next. It can be far from the code that filled the memory.- It is a fatal error: the script ends, the exit code of the CLI is 255, and a web request ends with a 500 (our Laravel route answered with its “Server Error” page). A
try/catchdoesn’t see it.
Common causes and fixes
- A whole result set or file loaded into an array:
fetchAll(),file(),Model::all()in Laravel. Read in chunks or one row at a time instead (cursor(),chunkById(), a generator). - A loop that accumulates: a list that grows with the data, a log or a cache kept in a static property. Keep what you need, not what you saw.
- A limit that is too low for the job: an import, an export or an image resize. Raise
memory_limitfor that job only (php -d memory_limit=512Mfor a CLI command), after measuring withmemory_get_peak_usage(true).
The same 1.5 million lines, with a 64 MiB limit: building the list ends with the fatal error above, reading them with a generator peaked at 2.0 MiB.
<?php
// 1.5 million lines, php -d memory_limit=64M
function allLines(int $n): array { // builds the whole list: Fatal error at 64 MiB
$r = [];
for ($i = 0; $i < $n; $i++) { $r[] = "order-$i,19.90,paid"; }
return $r;
}
function eachLine(int $n): Generator { // one line at a time: peak memory 2.0 MiB
for ($i = 0; $i < $n; $i++) { yield "order-$i,19.90,paid"; }
}
foreach (eachLine(1_500_000) as $line) { /* process $line */ }What the PHP SDK captures
The SDK registers a shutdown function and keeps 16 KiB in reserve, which it frees when the script dies so there is room to build the event (read in ErrorHandler.php; the same in the three versions below). For a memory error, it also raises memory_limit by 5 MiB, once, so it can send. With plain sentry/sentry 4.17.1, 4.27.0 and 4.38.0, one event arrived in each case:
\Sentry\init(['dsn' => 'https://<key>@ingest.errilo.com/<project>']);- Level
fatal, exception typeSentry\Exception\FatalErrorException, marked unhandled (handled: false). - The value is PHP’s message with the SDK’s own prefix:
Error: Allowed memory size of 33554432 bytes exhausted (tried to allocate 2097152 bytes). - A single frame: the file and the line where memory ran out, with no function name. The call stack PHP prints is not in the event: in our run,
error_get_last()has notraceentry for a memory error, even though it has one for a timeout. - In 4.38.0, the SDK strips the data of the breadcrumbs for this error, to spare memory.
With Laravel 13.43.0 and sentry/sentry-laravel 4.22.0, 4.26.0 and 4.31.0 (Integration::handles() in bootstrap/app.php), the error goes through Laravel’s own handler and the event differs:
->withExceptions(function (Exceptions $exceptions) {
Integration::handles($exceptions);
})- Exception type
Symfony\Component\ErrorHandler\Error\FatalError, with the message as PHP wrote it (noError:prefix), marked unhandled. - No
levelin the event, and the request (GETand the URL) is attached. Still one frame, the line of the route that ran out of memory. One event, not two.
The setup is in the Laravel guide. We did not run this error on Symfony; the Symfony guide covers the setup.
When the process is killed from outside, nothing is sent: PHP never reaches its shutdown function. That is what happens when a container’s memory limit is lower than memory_limit: the kernel stops the process first. We checked that a SIGKILL sends nothing (see the execution time page); we did not run a container with a memory limit.
How Errilo shows it
The issue is titled with the type and the whole message, numbers included (Sentry\Exception\FatalErrorException: Error: Allowed memory size of 33554432 bytes exhausted (tried to allocate 2097152 bytes)), with an Unhandled badge, level Fatal with the plain SDK and Error with Laravel, where the event has no level. Its location is the file of the single frame.
Errilo groups on the exception type and the frames, not on the message or the line. We ran Errilo’s grouping code on the events: two runs with a 32 MiB and a 64 MiB limit, in the same file, gave the same fingerprint, and so did a loop and a single 200 MiB allocation in another file. Two different files gave two issues. So one issue gathers every memory error that ends in the same file, whatever the limit and the size, and it points to where memory ran out. To find where it went, look at the breadcrumbs and the request, then profile.