189 8069 5689

php数据占用内存大小 php 内存占用

为什么我的PHP7.2.1内存最大限定5G,实际却无法超过1G

一般大型网站memory_limit用默认的128M都完全没问题,你的要5G?是要一次性处理几个G的POST数据吗?那肯定是你的程序有问题,一般情况下不需要这么大内存占用的。

成都创新互联主要从事网站设计制作、网站制作、网页设计、企业做网站、公司建网站等业务。立足成都服务蒙自,十多年网站建设经验,价格优惠、服务专业,欢迎来电咨询建站服务:028-86922220

以下是我个人看法,未经测试,权当参考:尽管你的系统是64位的,但你的PHP是32位的,因此最大的内存寻址范围也就是2G,再加上PHP本身的占用,实际可供分配的就是1G了。

因此我认为你目前的重点不是如何扩大PHP的内存限定,而是要优化你的脚本代码。

一个php-cgi占用系统多大内存

在网上翻阅资料的时候会看到有人说一个php-cgi进程大约占用系统内存20M,但是php-cgi占用内存其实是与你的php.ini配置加载多少个.so(.dll)模块相关的,我们在linux系统下查看,可以用pman的命令:

pmap $(pgrep php-cgi | head -1)

[root@Smile ~]# pmap $(pgrep php-cgi | head -1)

2830: /home/pubsrv/php/bin/php-cgi --fpm --fpm-config /home/pubsrv/php/etc/php-fpm.conf

0000000000400000 6852K r-x-- /home/pubsrv/php/bin/php-cgi

0000000000cb1000 268K rw--- /home/pubsrv/php/bin/php-cgi

0000000000cf4000 60K rw--- [ anon ]

00000000016fd000 2216K rw--- [ anon ]

0000003c24a00000 128K r-x-- /lib64/ld-2.12.so (deleted)

0000003c24c1f000 4K r---- /lib64/ld-2.12.so (deleted)

0000003c24c20000 4K rw--- /lib64/ld-2.12.so (deleted)

0000003c24c21000 4K rw--- [ anon ]

0000003c24e00000 8K r-x-- /lib64/libdl-2.12.so (deleted)

0000003c24e02000 2048K ----- /lib64/libdl-2.12.so (deleted)

0000003c25002000 4K r---- /lib64/libdl-2.12.so (deleted)

0000003c25003000 4K rw--- /lib64/libdl-2.12.so (deleted)

0000003c25200000 1576K r-x-- /lib64/libc-2.12.so (deleted)

0000003c2538a000 2044K ----- /lib64/libc-2.12.so (deleted)

0000003c25589000 16K r---- /lib64/libc-2.12.so (deleted)

0000003c2558d000 4K rw--- /lib64/libc-2.12.so (deleted)

0000003c2558e000 20K rw--- [ anon ]

0000003c25600000 92K r-x-- /lib64/libpthread-2.12.so (deleted)

0000003c25617000 2048K ----- /lib64/libpthread-2.12.so (deleted)

0000003c25817000 4K r---- /lib64/libpthread-2.12.so (deleted)

0000003c25818000 4K rw--- /lib64/libpthread-2.12.so (deleted)

0000003c25819000 16K rw--- [ anon ]

0000003c25a00000 28K r-x-- /lib64/librt-2.12.so (deleted)

0000003c25a07000 2044K ----- /lib64/librt-2.12.so (deleted)

0000003c25c06000 4K r---- /lib64/librt-2.12.so (deleted)

0000003c25c07000 4K rw--- /lib64/librt-2.12.so (deleted)

0000003c25e00000 524K r-x-- /lib64/libm-2.12.so (deleted)

0000003c25e83000 2044K ----- /lib64/libm-2.12.so (deleted)

0000003c26082000 4K r---- /lib64/libm-2.12.so (deleted)

0000003c26083000 4K rw--- /lib64/libm-2.12.so (deleted)

0000003c26200000 84K r-x-- /lib64/libz.so.1.2.3 (deleted)

0000003c26215000 2044K ----- /lib64/libz.so.1.2.3 (deleted)

0000003c26414000 4K r---- /lib64/libz.so.1.2.3 (deleted)

0000003c26415000 4K rw--- /lib64/libz.so.1.2.3 (deleted)

0000003c26600000 116K r-x-- /lib64/libselinux.so.1.#prelink#.YPfIAE (deleted)

0000003c2661d000 2044K ----- /lib64/libselinux.so.1.#prelink#.YPfIAE (deleted)

0000003c2681c000 4K r---- /lib64/libselinux.so.1.#prelink#.YPfIAE (deleted)

0000003c2681d000 4K rw--- /lib64/libselinux.so.1.#prelink#.YPfIAE (deleted)

0000003c2681e000 4K rw--- [ anon ]

0000003c26a00000 928K r-x-- /usr/lib64/libstdc++.so.6.0.13 (deleted)

0000003c26ae8000 2048K ----- /usr/lib64/libstdc++.so.6.0.13 (deleted)

0000003c26ce8000 28K r---- /usr/lib64/libstdc++.so.6.0.13 (deleted)

0000003c26cef000 8K rw--- /usr/lib64/libstdc++.so.6.0.13 (deleted)

0000003c26cf1000 84K rw--- [ anon ]

0000003c26e00000 88K r-x-- /lib64/libgcc_s-4.4.7-20120601.so.1;529c1fe4 (deleted)

0000003c26e16000 2044K ----- /lib64/libgcc_s-4.4.7-20120601.so.1;529c1fe4 (deleted)

0000003c27015000 4K rw--- /lib64/libgcc_s-4.4.7-20120601.so.1;529c1fe4 (deleted)

0000003c27200000 88K r-x-- /lib64/libresolv-2.12.so (deleted)

0000003c27216000 2048K ----- /lib64/libresolv-2.12.so (deleted)

0000003c27416000 4K r---- /lib64/libresolv-2.12.so (deleted)

0000003c27417000 4K rw--- /lib64/libresolv-2.12.so (deleted)

0000003c27418000 8K rw--- [ anon ]

0000003c27a00000 12K r-x-- /lib64/libplds4.so (deleted)

0000003c27a03000 2044K ----- /lib64/libplds4.so (deleted)

0000003c27c02000 4K r---- /lib64/libplds4.so (deleted)

0000003c27c03000 4K rw--- /lib64/libplds4.so (deleted)

0000003c27e00000 16K r-x-- /lib64/libplc4.so (deleted)

0000003c27e04000 2044K ----- /lib64/libplc4.so (deleted)

0000003c28003000 4K r---- /lib64/libplc4.so (deleted)

0000003c28004000 4K rw--- /lib64/libplc4.so (deleted)

0000003c28200000 228K r-x-- /lib64/libnspr4.so (deleted)

0000003c28239000 2048K ----- /lib64/libnspr4.so (deleted)

0000003c28439000 4K r---- /lib64/libnspr4.so (deleted)

0000003c2843a000 8K rw--- /lib64/libnspr4.so (deleted)

0000003c2843c000 8K rw--- [ anon ]

0000003c28600000 148K r-x-- /usr/lib64/libnssutil3.so (deleted)

0000003c28625000 2044K ----- /usr/lib64/libnssutil3.so (deleted)

0000003c28824000 24K r---- /usr/lib64/libnssutil3.so (deleted)

0000003c2882a000 4K rw--- /usr/lib64/libnssutil3.so (deleted)

0000003c28a00000 408K r-x-- /lib64/libfreebl3.so (deleted)

0000003c28a66000 2048K ----- /lib64/libfreebl3.so (deleted)

0000003c28c66000 4K r---- /lib64/libfreebl3.so (deleted)

0000003c28c67000 4K rw--- /lib64/libfreebl3.so (deleted)

0000003c28c68000 16K rw--- [ anon ]

0000003c28e00000 28K r-x-- /lib64/libcrypt-2.12.so (deleted)

0000003c28e07000 2048K ----- /lib64/libcrypt-2.12.so (deleted)

0000003c29007000 4K r---- /lib64/libcrypt-2.12.so (deleted)

0000003c29008000 4K rw--- /lib64/libcrypt-2.12.so (deleted)

0000003c29009000 184K rw--- [ anon ]

0000003c29200000 1236K r-x-- /usr/lib64/libnss3.so (deleted)

0000003c29335000 2044K ----- /usr/lib64/libnss3.so (deleted)

0000003c29534000 20K r---- /usr/lib64/libnss3.so (deleted)

0000003c29539000 8K rw--- /usr/lib64/libnss3.so (deleted)

0000003c2953b000 8K rw--- [ anon ]

0000003c29600000 160K r-x-- /usr/lib64/libsmime3.so (deleted)

0000003c29628000 2048K ----- /usr/lib64/libsmime3.so (deleted)

0000003c29828000 12K r---- /usr/lib64/libsmime3.so (deleted)

0000003c2982b000 4K rw--- /usr/lib64/libsmime3.so (deleted)

0000003c29a00000 204K r-x-- /usr/lib64/libssl3.so (deleted)

0000003c29a33000 2048K ----- /usr/lib64/libssl3.so (deleted)

0000003c29c33000 8K r---- /usr/lib64/libssl3.so (deleted)

0000003c29c35000 4K rw--- /usr/lib64/libssl3.so (deleted)

0000003c29c36000 4K rw--- [ anon ]

0000003c29e00000 12K r-x-- /lib64/libcom_err.so.2.1 (deleted)

0000003c29e03000 2044K ----- /lib64/libcom_err.so.2.1 (deleted)

0000003c2a002000 4K r---- /lib64/libcom_err.so.2.1 (deleted)

0000003c2a003000 4K rw--- /lib64/libcom_err.so.2.1 (deleted)

0000003c2a200000 100K r-x-- /usr/lib64/libsasl2.so.2.0.23.#prelink#.BXW3hH (deleted)

0000003c2a219000 2044K ----- /usr/lib64/libsasl2.so.2.0.23.#prelink#.BXW3hH (deleted)

0000003c2a418000 4K r---- /usr/lib64/libsasl2.so.2.0.23.#prelink#.BXW3hH (deleted)

0000003c2a419000 4K rw--- /usr/lib64/libsasl2.so.2.0.23.#prelink#.BXW3hH (deleted)

0000003c2aa00000 1488K r-x-- /usr/lib64/libcrypto.so.1.0.0 (deleted)

0000003c2ab74000 2044K ----- /usr/lib64/libcrypto.so.1.0.0 (deleted)

0000003c2ad73000 100K r---- /usr/lib64/libcrypto.so.1.0.0 (deleted)

0000003c2ad8c000 40K rw--- /usr/lib64/libcrypto.so.1.0.0 (deleted)

0000003c2ad96000 16K rw--- [ anon ]

0000003c2ae00000 56K r-x-- /lib64/liblber-2.4.so.2.5.6.#prelink#.IEslwN (deleted)

0000003c2ae0e000 2044K ----- /lib64/liblber-2.4.so.2.5.6.#prelink#.IEslwN (deleted)

0000003c2b00d000 4K r---- /lib64/liblber-2.4.so.2.5.6.#prelink#.IEslwN (deleted)

0000003c2b00e000 4K rw--- /lib64/liblber-2.4.so.2.5.6.#prelink#.IEslwN (deleted)

0000003c2b200000 608K r-x-- /usr/lib64/libfreetype.so.6.3.22.#prelink#.GI1Kfx (deleted)

0000003c2b298000 2044K ----- /usr/lib64/libfreetype.so.6.3.22.#prelink#.GI1Kfx (deleted)

0000003c2b497000 24K rw--- /usr/lib64/libfreetype.so.6.3.22.#prelink#.GI1Kfx (deleted)

0000003c2b600000 260K r-x-- /lib64/libgssapi_krb5.so.2.2.#prelink#.gjYRNu (deleted)

0000003c2b641000 2048K ----- /lib64/libgssapi_krb5.so.2.2.#prelink#.gjYRNu (deleted)

0000003c2b841000 4K r---- /lib64/libgssapi_krb5.so.2.2.#prelink#.gjYRNu (deleted)

0000003c2b842000 8K rw--- /lib64/libgssapi_krb5.so.2.2.#prelink#.gjYRNu (deleted)

0000003c2ba00000 148K r-x-- /usr/lib64/libpng12.so.0.49.0.#prelink#.cL7qH2 (deleted)

0000003c2ba25000 2048K ----- /usr/lib64/libpng12.so.0.49.0.#prelink#.cL7qH2 (deleted)

0000003c2bc25000 4K rw--- /usr/lib64/libpng12.so.0.49.0.#prelink#.cL7qH2 (deleted)

0000003c2be00000 292K r-x-- /lib64/libldap-2.4.so.2.5.6.#prelink#.QXZutL (deleted)

0000003c2be49000 2048K ----- /lib64/libldap-2.4.so.2.5.6.#prelink#.QXZutL (deleted)

total 286016K

[root@Smile ~]#

可以看到我的一个php-cgi占用了大约28M

php的最大内存限制是多少

这个看情况了,处理大数据肯定需要的内存更大,只是本地调试肯定用不了多少。

php.ini的内存限制默认为memory_limit = 128M,只要把memory_limit设为-1,就不会限制你跑cli脚本时的内存限制。

一般作为一台专门运行php的服务器,肯定要尽可能的把内存给于php运行,一台不够就追加。


网站题目:php数据占用内存大小 php 内存占用
文章地址:http://cdxtjz.cn/article/doshocd.html

其他资讯