PHP ini_set memory limit
Asked Answered
S

2

8

When we use ini_set like below in code, will memory limit be the same for all other codes? or only valid for in which code we added ?

ini_set('memory_limit', '512M');

Thanks

Superintendency answered 3/3, 2017 at 11:39 Comment(0)
E
5

It is only working for the file where it is written. Best way to change settings for multiple phps in the same folder are:

1. creating a file named ".htaccess" with the line

php_value memory_limit '512M'

Keep in mind, this only works, if you server configuration allowes "AllowOverride" directive for this directory

2. adding a own php with your config options as auto-prepend-file

You can do this in php.ini.

3. changing value of "memory_limit" directly in you php.ini

but this will take affect to ALL php-files you are running

Evanescent answered 3/3, 2017 at 11:52 Comment(4)
i dont want to change the default memory_limit ,just want to incerease it for specific php file , so when i add ini_set('memory_limit', '512M'); , then only for this file memory will be used to 512. other php file will use default limit . this is what i undertand.Superintendency
Yes thats correct, ini_set only affects THIS php and all files wich are included from this file.Evanescent
1. This solution is tied exclusively to Apache httpd. 2. This solution is slow. 3. This is The Right Way™ to do it (defined as: most portable, with best performance).Khrushchev
you can change the link from php.net/manual/de/ to php.net/manual/en/Compendious
H
1

It depends where you are adding.

If in a specific script then till that script is running. If setting at application level then it will be set for that specific application.

Hypotenuse answered 3/3, 2017 at 11:47 Comment(1)
if i add it in test.php then when we execute it , memory will be setted to 512M then after exiting from script , default memory limit(not 512M) will be used for other php file, right?Superintendency

© 2022 - 2024 — McMap. All rights reserved.