Home > Backend Development > PHP Tutorial > memory_limit和memory_get_usage的关系

memory_limit和memory_get_usage的关系

WBOY
Release: 2016-06-23 14:02:32
Original
993 people have browsed it

    我先在服务器上测试了下,当/etc/php.ini中memory_limit设置成16M时,memory_get_usage在页面上输出30135641,这时我就纳闷了,那个数字不就是30M么,比php.ini要大啊,怎么没报警。这两者有什么关系?望朋友们解惑!!!


回复讨论(解决方案)

修改 php.ini 需要重启web服务,你也可能改错了位置

memory_limit 是可以在程序里动态修改的

echo ini_get('memory_limit');//256Mini_set('memory_limit', '5M');echo ini_get('memory_limit');//5M
Copy after login

ini_set('memory_limit', '5M');$a = range(1, 60000);
Copy after login
Fatal error: Allowed memory size of 5242880 bytes exhausted (tried to allocate 36 bytes) in ...
$a = range(1, 58995);echo memory_get_usage() * Mb;
Copy after login
4.9964294433594
再加一就报错

版主讲得很详细,受教了。

哦,明白了,楼上的方法很好,谢谢咯,原来上面的那个数字我看错了,本来应该是3M的,我看错30M了

我去,2楼啥时插进来的,把分都给你了,本来是给1楼的

哈哈,捡了个便宜,谢谢啦

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template