Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ini_set/ini_get memory_limit restoring memory php

Tags:

php

php-ini


I am writing a script, where I need to set memory limit to something very high at a certain point. But, I need to restore memory limit after that.


But, ini_get returns -1 if your script has not called ini_set to set memory limit.
I am trying to do something like this :

$oldLimit  = ini_get("memory_limit");
ini_set("memory_limit", "220M");
do something 
//restore memory
ini_set("memory_limit", -1);

But, $oldLimit is -1.
what does -1 means in this scenario.
Thanks in advance.

like image 511
Ravish Avatar asked Jun 13 '26 14:06

Ravish


2 Answers

-1 means unlimited, or in other words, you are limited by the server's physical memory. So there is no point in setting the memory_limit to something high

like image 182
periklis Avatar answered Jun 16 '26 06:06

periklis


According to the docs, -1 means there is no memory limit (http://ca.php.net/manual/en/ini.core.php)

(Having said that, there could be other memory resrictions causing you grief.)

Also, the ini_set() only applies for the duration of that running script, and isn't permanent, nor does it apply to any other scripts running at that time, or in the future. So if you do make changes, you probably don't need to set them back as they will just fall back when the script ends.

like image 34
Robbie Avatar answered Jun 16 '26 07:06

Robbie



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!