PHP CLI "Allowed memory size exhausted" - Raise memory_limit in CI
A PHP CLI process - a console command, migration, or build step - exceeded PHP’s memory_limit and was killed. CLI PHP often inherits a finite limit from php.ini, and a memory-heavy command can blow past it in CI.
What this error means
A php bin/... command dies partway with "Allowed memory size of N bytes exhausted (tried to allocate …)". The same command may pass locally where the CLI memory_limit is higher or -1.
PHP Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to
allocate 4096 bytes) in /app/src/Importer.php on line 88Common causes
CLI memory_limit too low for the workload
The runner’s php.ini sets a finite CLI memory_limit (e.g. 128M). A bulk import, large dataset, or in-memory accumulation exceeds it.
Unbounded growth in the command
Loading an entire result set, building a giant array, or not freeing objects in a loop makes memory climb until it hits the limit.
How to fix it
Raise the limit for that command
Pass a higher (or unlimited) limit to the specific CLI invocation.
php -d memory_limit=512M bin/console app:import
# or unlimited for a one-off batch job
php -d memory_limit=-1 bin/console app:importSet a CLI default in the runner config
If many commands need headroom, raise the CLI memory_limit once.
# php.ini (CLI SAPI)
memory_limit = 512MReduce memory use in the command
- Stream/batch large datasets instead of loading everything at once.
- Free large objects and detach ORM entities inside loops.
- Profile with
memory_get_peak_usage()to find the spike.
How to prevent it
- Set a sensible CLI
memory_limitin the runner image. - Batch/stream large data instead of buffering it all in memory.
- Add
-d memory_limitto known heavy CLI steps in CI.