Skip to content

PHP memory_limit

matiasdelellis edited this page Aug 28, 2020 · 2 revisions

PHP Memory limit

Within the application we try to respect the maximum memory consumption according to the PHP configuration. This option is configured by editing the php.ini file, and changing the default value to the preferred value.

In this application the process that consumes more memory and is directly affected by this setting is the face detection itself. If you use small values, the process will have to use very small images for the analysis, and may lose detection of some faces. You can increase the value, and that will allow you to use larger images, but at sone point it is very difficult for you to achieve any real improvement, and the analysis of each image will be very slow.

Therefore, the minimum memory value will depend on each model (128MB for HOG, 1GB for CNN models), and the maximum will depend on your hardware, but neither is recommended that more than 4Gb

Configuration file:

This option is a standard php configuration, and therefore is located within your configuration file. Also note that some distributions separate the configuration into two files. When the result returns a value containing /cli/ as this case, you should also edit another file which you should look for, but it will be very similar to /etc/php/7.0/fpm/php.ini

matias@services:~$ php --ini | grep "Loaded Configuration File"
Loaded Configuration File:         /etc/php/7.0/cli/php.ini

Check current value:

matias@services:~$ php -i | grep memory_limit
memory_limit => 128M => 128M

Change value

Use your favorite editor to edit the php configuration file (In this case /etc/php/7.0/cli/php.ini and /etc/php/7.0/fpm/php.ini), looking for the memory_limit option and changing the value.

matias@services:~$ diff -u /etc/php/7.0/cli/php.ini.bak /etc/php/7.0/cli/php.ini
--- /etc/php/7.0/cli/php.ini.bak	2020-04-10 14:03:24.138229853 -0300
+++ /etc/php/7.0/cli/php.ini	2020-04-10 14:04:19.938457505 -0300
@@ -386,7 +386,7 @@
 
 ; Maximum amount of memory a script may consume (128MB)
 ; http://php.net/memory-limit
-memory_limit = 128M
+memory_limit = 2048M
 
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 ; Error handling and logging ;

It is recommended to restart the services that depend on this value.

matias@services:~$ sudo systemctl restart php7.0-fpm.service nginx.service `

Check the value.

matias@services:~$ php -i | grep memory_limit
memory_limit => 2048M => 2048M

Documentation: