search
HomeBackend DevelopmentPHP TutorialFatal error: Allowed memory size of 134217728 bytes exhauste_PHP教程

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
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
win10打开游戏fatal error怎么办?win10打开游戏fatal error怎么办?Feb 09, 2024 pm 12:54 PM

win10打开游戏fatalerror怎么办?我们在运行软件或者是游戏的时候会出现提示fatalerror错误怎么办?下面就让本站来为用户们来仔细的介绍一下win10打开游戏fatalerror的处理办法吧。win10打开游戏fatalerror怎么办?方法一:游戏客户端存在了问题,例如文件的损坏或者使用了一些破解补丁,都会导致fatalerror错误的出现,大家可以重新下载游戏。方法二:电脑内存太小也会导致fatalerror错误的出现,如果是物理内存足够的话,那么可以尝试设置一下系统的虚拟内

PHP Fatal error: Call to undefined method PDO::prepare() in的解决方法PHP Fatal error: Call to undefined method PDO::prepare() in的解决方法Jun 22, 2023 pm 06:40 PM

PHP作为一种流行的Web开发语言,已经被使用了很长时间。PHP中集成的PDO(PHP数据对象)类是我们在开发Web应用程序过程中与数据库进行交互的一种常用方法。但是,一些PHP开发者经常遇到的问题是,当使用PDO类与数据库进行交互时,他们会收到这样的错误:PHPFatalerror:CalltoundefinedmethodPDO::prep

解决C++代码中出现的“error: incomplete type is not allowed”问题解决C++代码中出现的“error: incomplete type is not allowed”问题Aug 26, 2023 pm 08:54 PM

解决C++代码中出现的“error:incompletetypeisnotallowed”问题在C++的编程过程中,有时候会遇到一些编译错误,其中一个常见的错误是“error:incompletetypeisnotallowed”。这个错误通常是由于在使用不完整的类型进行操作时引起的。本文将介绍这个错误的原因,并提供几种解决方法。首先,我

在Vue应用中使用axios时出现“Uncaught (in promise) Error: Request failed with status code 500”怎么办?在Vue应用中使用axios时出现“Uncaught (in promise) Error: Request failed with status code 500”怎么办?Jun 24, 2023 pm 05:33 PM

在Vue应用中使用axios是十分常见的,axios是一种基于Promise的HTTP客户端,可以用于浏览器和Node.js。在开发过程中,有时会出现“Uncaught(inpromise)Error:Requestfailedwithstatuscode500”的错误提示,对于开发者来说,这个错误提示可能有些难以理解和解决。本文将会探讨这

最终幻想7fatal error怎么解决最终幻想7fatal error怎么解决Mar 07, 2024 pm 04:40 PM

玩家在最终幻想7中进行游戏时,有很多玩家遇到了fatalerror的问题不知道怎么解决,通常是关于内存不能读取的问题,建议玩家尝试重装游戏解决。最终幻想7fatalerror怎么解决1、重装游戏游戏客户端问题,如文件损坏,不完整,使用了一些破解补丁都会导致致命错误的出现,建议重装游戏。2、把所有文件属性的只读去掉某些文件属性不该是只读而设置成了只读,把所有文件属性的只读去掉就行了,比如一款游戏不能玩,那么右键点击该游戏的安装文件夹,取消只读属性。3、设置虚拟内存可能是由于内存太小,如果物理内存足

0271:real time clock error开不开机怎么办0271:real time clock error开不开机怎么办Mar 13, 2023 am 11:30 AM

“0271:real time clock error”开不开机的解决办法:1、按一下F1,在出现的界面中,将选项栏转到第三项“Date/Time”;2、将系统时间手动修改成现在的时间;3、按F10,在弹出的对话框中,选择yes;4、重新打开笔记本即可正常开机。

解决C++代码中出现的“error: expected initializer before 'datatype'”问题解决C++代码中出现的“error: expected initializer before 'datatype'”问题Aug 25, 2023 pm 01:24 PM

解决C++代码中出现的“error:expectedinitializerbefore'datatype'”问题在C++编程中,有时候我们在编写代码时会遇到一些编译错误,其中一种常见的错误是“error:expectedinitializerbefore'datatype'”。这个错误通常在变量声明或函数定义中发生,可能导致程序无法正确编译或

如何解决PHP Warning: fopen(): failed to open stream: No such file or directory如何解决PHP Warning: fopen(): failed to open stream: No such file or directoryAug 19, 2023 am 10:44 AM

如何解决PHPWarning:fopen():failedtoopenstream:Nosuchfileordirectory在使用PHP开发过程中,我们经常会遇到一些文件操作的问题,其中之一就是"PHPWarning:fopen():failedtoopenstream:Nosuchfileordirectory

See all articles

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

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

Hot Tools

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

mPDF

mPDF

mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft