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教程

Jul 13, 2016 am 10:43 AM
bytes error fatal memory size exist

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. ...
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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

What to do if there is a fatal error when opening a game in win10? What to do if there is a fatal error when opening a game in win10? Feb 09, 2024 pm 12:54 PM

What should I do if there is a fatal error when opening a game in win10? What should we do if a fatal error message appears when running software or games? Let this site carefully introduce to users how to deal with the fatal error when opening games in Win10. What should I do if there is a fatal error when opening a game in win10? Method 1: There are problems with the game client, such as file damage or the use of some cracking patches, which will lead to fatalerror errors. You can re-download the game. Method 2: Too small computer memory can also cause fatalerror errors. If the physical memory is sufficient, you can try to set the virtual memory of the system.

Solution to PHP Fatal error: Call to undefined method PDO::prepare() in Solution to PHP Fatal error: Call to undefined method PDO::prepare() in Jun 22, 2023 pm 06:40 PM

PHP is a popular web development language that has been used for a long time. The PDO (PHP Data Object) class integrated in PHP is a common way for us to interact with the database during the development of web applications. However, a problem that some PHP developers often encounter is that when using the PDO class to interact with the database, they receive an error like this: PHPFatalerror:CalltoundefinedmethodPDO::prep

What should I do if 'Uncaught (in promise) Error: Request failed with status code 500' occurs when using axios in a Vue application? What should I do if 'Uncaught (in promise) Error: Request failed with status code 500' occurs when using axios in a Vue application? Jun 24, 2023 pm 05:33 PM

It is very common to use axios in Vue applications. axios is a Promise-based HTTP client that can be used in browsers and Node.js. During the development process, the error message "Uncaught(inpromise)Error: Requestfailedwithstatuscode500" sometimes appears. For developers, this error message may be difficult to understand and solve. This article will explore this

Use java's File.length() function to get the size of the file Use java's File.length() function to get the size of the file Jul 24, 2023 am 08:36 AM

Use Java's File.length() function to get the size of a file. File size is a very common requirement when dealing with file operations. Java provides a very convenient way to get the size of a file, that is, using the length() method of the File class. . This article will introduce how to use this method to get the size of a file and give corresponding code examples. First, we need to create a File object to represent the file we want to get the size of. Here is how to create a File object: Filef

How to solve the fatal error in Final Fantasy 7 How to solve the fatal error in Final Fantasy 7 Mar 07, 2024 pm 04:40 PM

When players play Final Fantasy 7, many players encounter fatal error problems and do not know how to solve them. It is usually about the problem that the memory cannot be read. It is recommended that players try to reinstall the game to solve the problem. How to solve the Final Fantasy 7 fatal error 1. Reinstall the game. Game client problems, such as file damage, incompleteness, and the use of some crack patches will lead to fatal errors. It is recommended to reinstall the game. 2. Remove the read-only properties of all files. Some file properties should not be read-only but are set to read-only. Just remove the read-only properties of all files. For example, if a game cannot be played, right-click on the game. Install the folder and cancel the read-only attribute. 3. Setting virtual memory may be due to the memory being too small. If the physical memory is sufficient

The first choice for CS players: recommended computer configuration The first choice for CS players: recommended computer configuration Jan 02, 2024 pm 04:26 PM

1. Processor When choosing a computer configuration, the processor is one of the most important components. For playing games like CS, the performance of the processor directly affects the smoothness and response speed of the game. It is recommended to choose Intel Core i5 or i7 series processors because they have powerful multi-core processing capabilities and high frequencies, and can easily cope with the high requirements of CS. 2. Graphics card Graphics card is one of the important factors in game performance. For shooting games such as CS, the performance of the graphics card directly affects the clarity and smoothness of the game screen. It is recommended to choose NVIDIA GeForce GTX series or AMD Radeon RX series graphics cards. They have excellent graphics processing capabilities and high frame rate output, and can provide a better gaming experience. 3. Memory power

Solve the 'error: expected initializer before 'datatype'' problem in C++ code Solve the 'error: expected initializer before 'datatype'' problem in C++ code Aug 25, 2023 pm 01:24 PM

Solve the "error:expectedinitializerbefore'datatype'" problem in C++ code. In C++ programming, sometimes we encounter some compilation errors when writing code. One of the common errors is "error:expectedinitializerbefore'datatype'". This error usually occurs in a variable declaration or function definition and may cause the program to fail to compile correctly or

Solve the problem of 'error: incomplete type is not allowed' in C++ code Solve the problem of 'error: incomplete type is not allowed' in C++ code Aug 26, 2023 pm 08:54 PM

Solve the "error:incompletetypeisnotallowed" problem in C++ code. During the C++ programming process, you sometimes encounter some compilation errors. One of the common errors is "error:incompletetypeisnotallowed". This error is usually caused by operating on an incomplete type. This article will explain the cause of this error and provide several solutions. firstly, I

See all articles