Home > Backend Development > PHP Tutorial > Fatal error: Allowed memory size of 134217728 bytes exhauste_PHP教程

Fatal error: Allowed memory size of 134217728 bytes exhauste_PHP教程

WBOY
Release: 2016-07-13 10:43:25
Original
2363 people have browsed it

When running dedecms, some friends will find that some pages will prompt Fatal error: Allowed memory size of 134217728 bytes exhauste. Let’s take a look at how to solve this problem.

Error message: Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 38218371 bytes) in .....

Solution:

1. Cancel the memory limit of PHP.
Add ini_set("memory_limit","-1");
in the php program 2. Modify the php memory limit according to your own needs and refer to the memory size of the machine, such as changing it to 1024M.
Add ini_set("memory_limit","1024M"); in the php program or change the corresponding location in php.ini to memory_limit = 1024M;

The meaning of memory limit


The relevant documentation in php explains memory_limit as follows:

memory_limit: integer

This command sets the maximum number of memory bytes that a script can apply for. This helps prevent poorly written scripts from eating up the available memory on the server. To use this directive it must be enabled at compile time. Therefore the configure line should include: --enable-memory-limit. If no memory limit is required, it must be set to -1. From php 4.3.2 onwards, when memory_limit is activated, the PHP function memory_get_usage() can be used. In other words, the memory limit of PHP processing in a page is defined as 128M by default (/etc/php.ini) (after the default installation of my system). Later, the development team's applications became more and more complex, but in There may be some structural deficiencies, and frequent object requests actually cause insufficient memory.

Application level testing and solutions

The best way should be solved at the application level instead of constantly increasing memory settings. The following is the code test:

memory usage: 77.09 M
The code is as follows
 代码如下 复制代码

printf(" total run: %.2f s
".
"memory usage: %.2f M
",
microtime(true)-$HeaderTime,
memory_get_usage() / 1024 / 1024 );
?>

Copy code

printf(" total run: %.2f s
".

"memory usage: %.2f M
",

microtime(true)-$HeaderTime,

memory_get_usage() / 1024 / 1024 );
?>

The running results are shown as follows:

total runtime: 1.47 s

One page actually has 77M requests. The reason is that when coding, programmers only assign values ​​to variables, but never unset ($var). Just imagine, if a page request needs to process 20 SQL queries, each SQL query returns 10 SQL results, and the programmer never cares whether to return all the columns of a row or only the required columns (in fact, when we use a more common In the middle layer, all columns are often returned instead of specific fields, just like in ORM such as NHibernate and JBOSS. If a row has 10K, then the page will be increased to 10K by the end of processing. 10K*10*20=2M array allocation, not counting the times when we need to copy the most arrays.

Talk from experience I have a server using apaceh2.3 and php5.2.6. The above method is invalid. It has been officially confirmed that it is a bug in the php version. We can change it to a higher version and use the php version to solve the problem.
http://www.bkjia.com/PHPjc/633175.htmlwww.bkjia.com
truehttp: //www.bkjia.com/PHPjc/633175.htmlTechArticleWhen running dedecms, some friends will find that some pages will prompt Fatal error: Allowed memory size of 134217728 bytes exhauste error. , let’s take a look at how to solve this problem. ...
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template