Memory allocation error but no php.ini how to modify memory setting
Closed this issue ยท 4 comments
2018-09-18 17:20:08 Error: Fatal Error (1): Allowed memory size of 134217728 bytes exhausted (tried to allocate 4096 bytes) in [/var/www/html/vendor/cakephp/cakephp/src/Database/Statement/PDOStatement.php, line 71]
Request URL: /admin/recons/upload
Referer URL: https://xx.com/admin/recons/upload
Client IP: 211.24.107.194
Trace:
Cake\Error\BaseErrorHandler::handleFatalError() - CORE/src/Error/BaseErrorHandler.php, line 223
Cake\Error\BaseErrorHandler::Cake\Error{closure}() - CORE/src/Error/BaseErrorHandler.php, line 104
[main] - [internal], line ??
root@569d9c5af48f:/var/www/html# php --ini
Configuration File (php.ini) Path: /usr/local/etc/php
Loaded Configuration File: (none)
Scan for additional .ini files in: /usr/local/etc/php/conf.d
Additional .ini files parsed: /usr/local/etc/php/conf.d/docker-php-ext-bcmath.ini,
/usr/local/etc/php/conf.d/docker-php-ext-bz2.ini,
/usr/local/etc/php/conf.d/docker-php-ext-calendar.ini,
/usr/local/etc/php/conf.d/docker-php-ext-exif.ini,
/usr/local/etc/php/conf.d/docker-php-ext-gd.ini,
/usr/local/etc/php/conf.d/docker-php-ext-gettext.ini,
/usr/local/etc/php/conf.d/docker-php-ext-intl.ini,
/usr/local/etc/php/conf.d/docker-php-ext-ldap.ini,
/usr/local/etc/php/conf.d/docker-php-ext-mcrypt.ini,
/usr/local/etc/php/conf.d/docker-php-ext-memcached.ini,
/usr/local/etc/php/conf.d/docker-php-ext-mysqli.ini,
/usr/local/etc/php/conf.d/docker-php-ext-opcache.ini,
/usr/local/etc/php/conf.d/docker-php-ext-pdo_mysql.ini,
/usr/local/etc/php/conf.d/docker-php-ext-pdo_pgsql.ini,
/usr/local/etc/php/conf.d/docker-php-ext-pgsql.ini,
/usr/local/etc/php/conf.d/docker-php-ext-redis.ini,
/usr/local/etc/php/conf.d/docker-php-ext-soap.ini,
/usr/local/etc/php/conf.d/docker-php-ext-zip.ini
You can just create new ini files in conf.d
.
I use a Dockerfile
and define your settings like something like this:
RUN echo 'max_execution_time=240' >> /usr/local/etc/php/conf.d/php.ini \
&& echo 'memory_limit=1G' >> /usr/local/etc/php/conf.d/php.ini
@Nemo64 i don't have php.ini inside the docker how do i do this?
Hi @manzurshaikh ! Thanks for your interest in this project.
By following what @Nemo64 suggested, you actually create a php.ini
in your Docker image, even if you didn't have one.
You can actually do a few different things, depending on your use case:
Generate a php.ini
at build time
If you're building your own image on top of a chialab/php:whatever
image, you can add the instruction suggested by Nemo in your Dockerfile
that will write the pieces of configuration in the php.ini
file:
FROM chialab/php:whatever
# ...
# Add this part:
RUN echo 'max_execution_time=240' >> /usr/local/etc/php/conf.d/php.ini \
&& echo 'memory_limit=1G' >> /usr/local/etc/php/conf.d/php.ini
Then build your image as usual with docker build -t your/tag:name .
and in your image, PHP will be configured to use 1G memory and to last scripts execution for at most 240s.
OR, if you want, you can:
-
create a
php.ini
in your repository:max_execution_time=240 memory_limit=1G
-
add this file at build time:
FROM chialab/php:whatever # ... # Add this part: ADD php.ini /usr/local/etc/php/conf.d/php.ini
These two options are absolutely equivalent. I personally find the solution with the external file to be slightly clearer and easier to maintain, but that's a matter of personal taste.
Add a php.ini
at runtime
If you don't want or can't create your own image, and you're just running a container with chialab/php:whatever
image, you can still add your own configuration at runtime using Docker volumes:
-
Create a
php.ini
in the computer/server where Docker container is started:max_execution_time=240 memory_limit=1G
-
Mount the
php.ini
as a read-only volume when you start the container:$ docker run --name=my-container \ -v /path/to/php.ini:/usr/local/etc/php/conf.d/php.ini:ro \ chialab/php:whatever
Thanks, issue has been resolved ๐