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:
The code is as follows
|
Copy code
|
||||
printf(" total run: %.2f s ".
"memory usage: %.2f M
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.
http://www.bkjia.com/PHPjc/633175.htmlwww.bkjia.comtruehttp: //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. ...