In PHP5, the setting of memory_limit has been expanded from the previous 8M to the upper limit of 128M.
The explanation for the definition in the configuration is:
memory_limit = 128M ; Maximum amount of memory a script may consume (128MB)
Maximum independent memory usage of a single thread. That is, a web request gives the definition of the maximum memory usage of the thread.
In most existing website or forum applications, the application software is generally configured in the following form:
Nginx (Apache) PHP Memcache Mysql
For the use of the above application software , I won’t say more about the advantages. But the use of Memcache is to reduce the frequency of database access, and it is also a way to improve service response. However, the difference between memcache and database data storage is that memcache data is not stored in the memory in the form of the above data, but is abstracted and stored in the memory in the form of characters and hash tables. This storage difference leads to the fact that every time memcache data is extracted, all the data must be simulated in reverse order, and all the data must be imported into a single independent thread. Then the second part is to filter and extract the data you need.
During the application process, if you are reading data from the database, you should know that the optimization method should be to ensure that the first filtering in the SQL statement is as accurate as possible, and only take the required fields, not all of them. After taking out the fields, you can then filter them in the application to get the fields you want. This will make a fundamental difference in the load on the server.
If you use memcache, you will definitely not be able to accurately filter the database in the first time. Then you need to take this into consideration when you start designing the table, and try to ensure that the memcache data table has as little data as possible. This can be done by dividing the table into multiple tables.
The memory allocation of memory_limit is 128M as standard.
Once the independent thread exceeds 128M, PHP will report an error:
Fatal error: Allowed memory size of 33554432 bytes
For a server with 8G memory, if the concurrent responses reach 50 at the same time, each one is 128M peak, that is probably when the server will get stuck.
Try to reduce the memory configuration to 128M. If it is adjusted to 64M, the load of the server can be basically reduced by about half. If it can be adjusted to 32M, the effect will be better.
However, the requirements for applications are even higher. This issue is not considered in the early stages of establishment of many tables. If you want to use memcache as data storage, you must complete the design and deployment of optimized data tables in advance to reduce the memory usage of independent thread PHP. With the volume, the server response and load are reduced by more than just a few percentage points.