How to get the real memory limit in a PHP script?

余生长醉 提交于 2020-12-12 02:05:21

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!