问题
Using ini_get('memory_limit') will get what is specified in the php.ini file (i presume). But if i run ini_set('memory_limit', 'somethingInsanelyHigh') and then run ini_get(..) again, it will return what i previously set it to. This brings me to believe there's no real way to increase the memory limit and detect if it's actually increased, is there?
What does ini_set(..) actually do? Does it just update a variable somewhere or does it actually increase the limit? And if so, how do i know if it worked or not?
回答1:
ini_set returns the old value on success, or FALSE on failure. So you might want to check it:
if (ini_set('memory_limit', 'somethingInsanelyHigh') === false) {
// cannot set memory_limit
}
Also, take into account that this will set the maximum amount of memory that the current PHP process will take, so if you are going to have multiple concurrent requests to this script, you will want to have something reasonable, in case your script really eats so much memory.
Also setting it to -1 means no memory limit.
edited: disabling memory limit is setting the value to -1, not setting it to 0.
来源:https://stackoverflow.com/questions/15790808/how-to-get-the-real-memory-limit-in-a-php-script