一般大型網(wǎng)站memory_limit用默認(rèn)的128M都完全沒問題,你的要5G?是要一次性處理幾個(gè)G的POST數(shù)據(jù)嗎?那肯定是你的程序有問題,一般情況下不需要這么大內(nèi)存占用的。
成都創(chuàng)新互聯(lián)主要從事網(wǎng)站設(shè)計(jì)制作、網(wǎng)站制作、網(wǎng)頁設(shè)計(jì)、企業(yè)做網(wǎng)站、公司建網(wǎng)站等業(yè)務(wù)。立足成都服務(wù)蒙自,十多年網(wǎng)站建設(shè)經(jīng)驗(yàn),價(jià)格優(yōu)惠、服務(wù)專業(yè),歡迎來電咨詢建站服務(wù):028-86922220
以下是我個(gè)人看法,未經(jīng)測試,權(quán)當(dāng)參考:盡管你的系統(tǒng)是64位的,但你的PHP是32位的,因此最大的內(nèi)存尋址范圍也就是2G,再加上PHP本身的占用,實(shí)際可供分配的就是1G了。
因此我認(rèn)為你目前的重點(diǎn)不是如何擴(kuò)大PHP的內(nèi)存限定,而是要優(yōu)化你的腳本代碼。
在網(wǎng)上翻閱資料的時(shí)候會(huì)看到有人說一個(gè)php-cgi進(jìn)程大約占用系統(tǒng)內(nèi)存20M,但是php-cgi占用內(nèi)存其實(shí)是與你的php.ini配置加載多少個(gè).so(.dll)模塊相關(guān)的,我們在linux系統(tǒng)下查看,可以用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 ~]#
可以看到我的一個(gè)php-cgi占用了大約28M
這個(gè)看情況了,處理大數(shù)據(jù)肯定需要的內(nèi)存更大,只是本地調(diào)試肯定用不了多少。
php.ini的內(nèi)存限制默認(rèn)為memory_limit = 128M,只要把memory_limit設(shè)為-1,就不會(huì)限制你跑cli腳本時(shí)的內(nèi)存限制。
一般作為一臺(tái)專門運(yùn)行php的服務(wù)器,肯定要盡可能的把內(nèi)存給于php運(yùn)行,一臺(tái)不夠就追加。