memory_limit php.ini vs ini_set('memory_limit','4096M')

262 Views Asked by At

I had a debate with my boss.

Which one is more convenient, efficient, standard.

Do we apply memory_limit in php.ini
or
do we just insert a code in php files like this ini_set('memory_limit','4096M');

Which kind are you?

1

There are 1 best solutions below

3
xprilion On

Changing the memory_limit in php.ini file will change it for all your PHP scripts running on that executable.

Using the ini_set will modify the configuration only for the script in which it is called and will end with the completion of the script's execution.

In a nutshell, the first one is a system-wide permanent change and the other one is a local to script change only during runtime.

Ref: PHP: ini_set - Manual, PHP Memory limit increase