Set the memory of PHP

All answers the question of mas Subhan about the memory settings of the PHP process. Sometimes a PHP script appears fatal error because it runs out of memory and this is the easiest solution yes we increase the limit on how much RAM is allocated. For his own way is very easy and there are several ways that can be applied.

How to set the maximum memory of PHP? It’s best if we set it directly in the configuration file (php.ini) and search:

; Maximum amount of memory a script may consume (128MB)
memory_limit = 128M

In the above code snippet can be seen the memory quota of a PHP script when executed. The units are MegaByte. I suggest do not pass from half of your VPS RAM because this rule per PHP script, if there are many that run at the same time can crash your VPS when it runs out of memory. And do not forget to restart PHP-FPMnya to read the new configuration. What if we do not have access to PHP settings? Alternatively, you can pass .htaccess file, just add this code in it:

php_value memory_limit 128M

Through .htaccess is less powerful? Last can also in PHP script itself, declare at the beginning yes:


Know where we have successfully set the memory limitnya? Use phpinfo (); will be seen later specifications of the current PHP engine. All of the above can be used to change the ration of RAM that can be utilized a PHP script. Just different levels of application only. If you change the memory limit value using php.ini it applies to all executed PHP code, if .htaccess increase the memory limit yes it applies to one site, and the smallest reach is through PHP code because it is only valid for one script that’s the limit. Note. So if we set the limit of RAM that can be used per process on Linux then the rules apply globally, no process is not affected. But if we set it from the PHP side then this limitation itself. In short the PHP configuration can not skip the Linux settings.

Pos terkait

Tinggalkan Balasan

Alamat email Anda tidak akan dipublikasikan. Ruas yang wajib ditandai *

Situs ini menggunakan Akismet untuk mengurangi spam. Pelajari bagaimana data komentar Anda diproses.