简体   繁体   English

ini_set / ini_get memory_limit恢复内存php

[英]ini_set/ini_get memory_limit restoring memory php


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. 但是,如果您的脚本没有调用ini_set来设置内存限制,则ini_get返回-1。
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. 但是, $ oldLimit是-1。
what does -1 means in this scenario. 在这种情况下-1是什么意思。
Thanks in advance. 提前致谢。

-1 means unlimited, or in other words, you are limited by the server's physical memory. -1表示无限制,换句话说,您受服务器的物理内存限制。 So there is no point in setting the memory_limit to something high 因此将memory_limit设置为高位是没有意义的

According to the docs, -1 means there is no memory limit (http://ca.php.net/manual/en/ini.core.php) 根据文档,-1表示没有内存限制(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. 此外,ini_set()仅适用于该运行脚本的持续时间,并且不是永久性的,也不适用于当时或将来运行的任何其他脚本。 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. 因此,如果您确实进行了更改,则可能不需要将它们重新设置,因为它们会在脚本结束时退回。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM