PHP5中,对于memory_limit的设定已经从以往的8M扩大到128M的上限。 对于配置中的定义解释是: memory_limit = 128M ; Maximum amount of memory a script may consume (128MB) 最大单线程的独立内存使用量 。也就是一个web请求,给予线程最大的内存使用量的
PHP5中,对于memory_limit的设定已经从以往的8M扩大到128M的上限。
对于配置中的定义解释是:
memory_limit = 128M ; Maximum amount of memory a script may consume (128MB)
最大单线程的独立内存使用量。也就是一个web请求,给予线程最大的内存使用量的定义。
现有的大部分网站或者论坛应用中,应用软件的配备一般都是以如下的形式搭建:
Nginx(Apache) PHP Memcache Mysql
对于以上的应用软件的采用,优点我就不再多说。但对于Memcache的使用就是为了减少对于数据库的访问的频率的降低,也是提高服务响应的一种办法。但是对于memcache和数据库的数据存储有区别的是,memcache的数据并不是以上数据的形式存储在内存中,而是抽象化了之后以字符的形式,hash 表的形式存储在内存之中。这样的存储区别导致,每次memcache的数据抽取必须全部数据反序拟化一次,将所有的数据导入进独立的单一线程中,然后第二部才是进行过滤和抽取你所需要的数据。
在应用过程中,如果是读取数据库的数据,大家应该知道,优化的办法应该是在SQL语句中比保证第一次过滤尽量是提高准确性,只取需要的字段,不要全部所有字段取出之后再在应用中过滤得到自己想要的字段,这样对于服务器的负载会有本质的区别。
如果采用memcache,必然做不到数据库在在第一次就精确过滤这点目标。那么就需要在开始设计表的同时就需要考虑到这点,尽量保证被memcache数据表尽量保证数据的较少,可以多分表来完成。
memory_limit的内存分配,标配是128M。
一旦独立的线程超过了128M,那PHP会报错:
Fatal error: Allowed memory size of 33554432 bytes
对于8G内存的服务器,如果同时并发的响应达到50,每个都是128M的峰值,那估计也是服务器会卡死的时候。
尽量降低128M的内存配置,如果调整至64M,服务器的负载基本能下降一半左右,如果能调整至32M效果更好。
但是对于应用的要求就更高,很多表建立初期就没有考虑到这个问题,如果你要采用memcache作为数据的存储,必须提前完成优化数据表的设计部署,降低独立线程PHP的内存使用量,服务器的响应和负载降低的就不仅仅是几个百分点的效果了。
原文地址:PHP5配置memory_limit参数讲解(转), 感谢原作者分享。

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

SublimeText3 Chinese version
Chinese version, very easy to use

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.
