In the run Dedecms is some friends will find some pages will prompt fatal error:allowed memory size of 134217728 bytes Exhauste error, let's take a look at the solution to this problem.
Error hint: Fatal error:allowed memory size of 134217728 bytes exhausted (tried to allocate 38218371 bytes) in .....
Workaround:
1. Remove the PHP memory limit.
Add Ini_set ("Memory_limit", "1") to the PHP program;
2. Modify the PHP memory limit according to your own needs and refer to the memory size of this machine, such as 1024M instead.
Add Ini_set ("Memory_limit", "1024M") to the PHP program; or change the corresponding position in php.ini to Memory_limit = 1024M;
The meaning of memory limits
The relevant documentation in PHP is explained Memory_limit as follows:
Memory_limit:integer
This directive sets the maximum number of bytes of memory that a script can request. This helps prevent poorly written scripts from consuming the available memory on the optical server. To use this directive, it must be activated at compile time. Therefore, the Configure line should include:--enable-memory-limit. If you do not need any memory restrictions, you must set it to-1. from PHP 4.3.2, when the memory_limit,php function Memory_get_usage () is activated, it can be used. That is, PHP in a page processing memory limit, the default (/etc/php.ini) is defined as 128M (after my system is installed by default), later development group application write more and more complex, but there may be some lack of structure, frequent object requests, actually caused the memory shortage.
Application-level testing and solving methods
The best way to do this is to address it at the application level instead of constantly adding memory settings. Here is the code test:
| The code is as follows |
Copy Code |
|
printf ("Total run:%.2f s
".
"Memory Usage:%.2f M
",
Microtime (True)-$HeaderTime,
Memory_get_usage ()/1024/1024);
?> |
The results of the operation are shown below:
Total runtime:1.47 S
Memory usage:77.09 M
A page will actually have a 77M request. The reason is that when programmers encode, they only assign values to variables, but never unset ($var). Imagine, if a page requests to process 20 SQL queries, each SQL query returns 10 SQL results, and the programmer never cares whether to return all the column of a row or simply return the required column (in fact, when we adopt a more common middle tier, tend to return all columns instead of certain fields, as in ORM (as in NHibernate, JBoss) If a row has 10K, then the page will be added to the 10K*10*20=2M array assignment at the end of the processing. It doesn't count. Sometimes we need the most arrays to replicate.
Therefore, in PHP, the reasonable method is to use the variable after the unset ($var), the maximum memory resource savings.
Experience
I have a server using apaceh2.3 and php5.2.6 above method invalid, officially confirmed to be a PHP version of the bug, we can change a high version of the manual PHP version can be resolved.
http://www.bkjia.com/PHPjc/633175.html www.bkjia.com true http://www.bkjia.com/PHPjc/633175.html techarticle in the run Dedecms is some friends will find some pages will prompt fatal error:allowed memory size of 134217728 bytes Exhauste error, let's take a look at the solution to this problem. ...