Recommended way to increase PHP memory limit in Docker

I have run into issues :::

PHP Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 20480 bytes)

The PHP limit of 128M may not be sufficient for my app, what is the recommended way to increase this limit via the Dockerfile ?


Does this happen in your builds while deploying, or during normal application running?

Is it related to uploading files?

We’re working on updating the Docker setup (which will make this particular task easier!).

In the meantime, edit your file (in your code base) docker/php.ini and increase the memory limit there. Those changes should get pulled in when you depot next.

Note that it’s possible you’ll need to set other settings if you’re uploading larger files.

Hi, yes happens in-app after normal deployment. Occurs as a file is downloaded to persistent storage for processing (via file stream)

The docker/php.ini file is used to set some settings for PHP. It looks like this.

Update these:

post_max_size = 2M
upload_max_filesize = 0M
memory_limit = 128M

Based on your error message it sounds like it’s related to memory_limit specifically. Do you know how large the file is? Using streaming should, in theory, be efficient enough to not need a high PHP limit. But if you need to increase the memory limit, you can!

Don’t forget your Fly virtual machine has its own cap on memory usage (default of 256m for the free tier).

Thanks, Chris, all solved. On a side topic, you may want to adjust the generated Laravel docker/supervisor.conf entry for the queue worker command, it contains a hardcoded ‘sqs’ connection. It took me a little while to find out why my log was filling with AWS SQS error messages!

-command=php /var/www/html/artisan queue:work sqs --sleep=3 --tries=3 --backoff=3 --max-time=3600
+command=php /var/www/html/artisan queue:work --sleep=3 --tries=3 --backoff=3 --max-time=3600

Right on!

That’s actually changing a lot soon, coming in the next flyctl release. I’ll be re-documenting how to accomplish cron and queue workers, as it’ll change a bit.

(The new setup will be easier to adjust in a few ways).

no problem let me know how to keep up-to-date with changes ?

i’m gonna be updating the docs on Tuesday (hopefully sooner).

The new base containers being used are here: GitHub - serversideup/docker-php: Production-ready Docker images for PHP. Optimized for Laravel, WordPress, and more!

Note the env vars you can use to increase memory limits.

I still need to investigate if they need to be set at build time or run time!