PHP memory limit allowed memory size of 134217728 bytes exhausted (tried to allocate 1099 bytes) in

Source: Internet
Author: User
Tags memory usage

Fatal error:allowed memory size of 134217728 bytes exhausted (tried to allocate 1099 bytes)
Fatal error:allowed memory size of 134217728 bytes exhausted (tried to allocate 1099 bytes)

Explanation is that the available memory is depleted, which is related to the setup of PHP Memory_limit.

There are two ways of solving this problem.

1. Modify PHP.ini

Memory_limit = 128 This method requires a reboot of the server, which is clearly limited to virtual machines.

2, through the Ini_set function to modify the configuration option value Ini_set (' Memory_limit ', ' 128M ')

Ini_set (' Memory_limit ', ' 128M ')

----------------

In PHP5, the setting for Memory_limit has been extended from the previous 8M to the upper limit of 128M. For the definition in configuration, the explanation is: Memory_limit = 128M; Maximum amount of memory of a script may consume (128MB) the maximum number of separate memory usage for a single thread. That is, a Web request that gives the thread the maximum memory usage definition. Most of the existing Web site or forum applications, application software is generally equipped with the following form: Nginx (Apache) +php+memcache+mysql for the above application software, the advantages I will not say more. But the use of memcache is to reduce the frequency of access to the database, but also a way to improve service response. But the difference between memcache and database data storage is that memcache data is not stored in memory in the form of the above data, but is abstracted and stored in memory in the form of a character, a hash table. This storage difference leads to the fact that each memcache data extraction must be fully sequenced, and all data is imported into a single, separate thread, and then the second is to filter and extract the data you need. In the application process, if you are reading the data of the database, you should know that the optimization method should be in the SQL statement than to ensure that the first filter is to improve accuracy, only take the required fields, do not all the fields out of the application of the filter to get the fields you want, This will have an essential difference to the load on the server.
If the use of memcache, it is inevitable that the database in the first time to accurately filter this goal. Then you need to start designing the table at the same time need to take this into account, as far as possible to ensure that the Memcache data table as much as possible to ensure that less data, can be more than a table to complete.
Memory_limit memory allocation, standard is 128M. Once the independent thread exceeds 128M, PHP will complain: Fatal error:allowed memory size of 33554432 bytes for 8G memory server, if concurrent response to reach 50, each is 128M peak, that is also a service When the device will be stuck to death.
As far as possible to reduce the 128M memory configuration, if the adjustment to 64M, the server's load can be reduced by about half, if you can adjust to 32M effect better. But for the application requirements are higher, many tables are not considered at the beginning of the problem, if you want to use Memcache as data storage, must be completed in advance to optimize the data table design deployment, reduce the independent thread PHP memory usage, The response and load of the server are reduced by more than just a few percent effect.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.