memory_get_peak_usage和实际php进程的内存使用量之间的区别 [英] Difference between memory_get_peak_usage and actual php process' memory usage

查看:55
本文介绍了memory_get_peak_usage和实际php进程的内存使用量之间的区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么在Linux中使用"top"或"ps"命令时,php memory_get_peak_usage的结果与显示为分配给进程的内存大小有很大不同?

Why result of php memory_get_peak_usage differs so much from memory size that is shown as allocated to process when using 'top' or 'ps' commands in Linux?

我在php.ini中设置了2 Mb的memory_limit 我的单字符串php-script与

I've set 2 Mb of memory_limit in php.ini My single-string php-script with

echo memory_get_peak_usage(true);

说它正在使用786432字节(768 Kb)

says that it is using 786432 bytes (768 Kb)

如果我尝试向系统询问有关当前php进程的信息

If I try to ask system about current php process

echo shell_exec('ps -p '.getmypid().' -Fl');

它给了我

F S UID        PID  PPID  C PRI  NI ADDR SZ WCHAN    RSS PSR STIME TTY          TIME CMD
5 S www-data 14599 14593  0  80   0 - 51322 pipe_w  6976   2 18:53 ?        00:00:00 php-fpm: pool www                                      

RSS参数为6976,因此内存使用率为6976 * 4096 = 28573696 =〜28 Mb

RSS param is 6976, so memory usage is 6976 * 4096 = 28573696 = ~28 Mb

28 Mb来自何处,有什么方法可以减少php-fpm进程正在使用的内存大小?

Where that 28 Mb come from and is there any way to decrease memory size that is being used by php-fpm process?

推荐答案

PHP进程本身主要使用内存大小. memory_get_peak_usage()返回您的特定脚本使用的内存.减少内存开销的方法是删除扩展的数量,静态编译PHP等.但是请不要忘记php-fpm(应该)派生,并且在很多PHP进程之间没有什么不同的内存使用情况事实共享(直到它改变).

The memory size is mostly used by the PHP process itself. memory_get_peak_usage() returns the memory used by your specific script. Ways to reduce the memory overhead is to remove the number of extensions, statically compile PHP, etc.. But don't forget that php-fpm (should) fork and that a lot of the memory usage that's not different between PHP process is in fact shared (until it changes).

这篇关于memory_get_peak_usage和实际php进程的内存使用量之间的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆