• <legend id='0qgqq'><style id='0qgqq'><dir id='0qgqq'><q id='0qgqq'></q></dir></style></legend>
      • <bdo id='0qgqq'></bdo><ul id='0qgqq'></ul>

        <small id='0qgqq'></small><noframes id='0qgqq'>

        <i id='0qgqq'><tr id='0qgqq'><dt id='0qgqq'><q id='0qgqq'><span id='0qgqq'><b id='0qgqq'><form id='0qgqq'><ins id='0qgqq'></ins><ul id='0qgqq'></ul><sub id='0qgqq'></sub></form><legend id='0qgqq'></legend><bdo id='0qgqq'><pre id='0qgqq'><center id='0qgqq'></center></pre></bdo></b><th id='0qgqq'></th></span></q></dt></tr></i><div id='0qgqq'><tfoot id='0qgqq'></tfoot><dl id='0qgqq'><fieldset id='0qgqq'></fieldset></dl></div>

        <tfoot id='0qgqq'></tfoot>

        诊断内存泄漏 - 已用完 # 字节的允许内存大小

        Diagnosing Memory Leaks - Allowed memory size of # bytes exhausted(诊断内存泄漏 - 已用完 # 字节的允许内存大小)

          <i id='HoXXZ'><tr id='HoXXZ'><dt id='HoXXZ'><q id='HoXXZ'><span id='HoXXZ'><b id='HoXXZ'><form id='HoXXZ'><ins id='HoXXZ'></ins><ul id='HoXXZ'></ul><sub id='HoXXZ'></sub></form><legend id='HoXXZ'></legend><bdo id='HoXXZ'><pre id='HoXXZ'><center id='HoXXZ'></center></pre></bdo></b><th id='HoXXZ'></th></span></q></dt></tr></i><div id='HoXXZ'><tfoot id='HoXXZ'></tfoot><dl id='HoXXZ'><fieldset id='HoXXZ'></fieldset></dl></div>

                <tbody id='HoXXZ'></tbody>

            • <small id='HoXXZ'></small><noframes id='HoXXZ'>

                • <bdo id='HoXXZ'></bdo><ul id='HoXXZ'></ul>
                  <tfoot id='HoXXZ'></tfoot>
                • <legend id='HoXXZ'><style id='HoXXZ'><dir id='HoXXZ'><q id='HoXXZ'></q></dir></style></legend>
                • 本文介绍了诊断内存泄漏 - 已用完 # 字节的允许内存大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我遇到了可怕的错误消息,可能是经过艰苦的努力,PHP 内存不足:

                  I've encountered the dreaded error-message, possibly through-painstaking effort, PHP has run out of memory:

                  第 123 行的 file.php 中 #### 字节的允许内存大小耗尽(尝试分配 #### 字节)

                  Allowed memory size of #### bytes exhausted (tried to allocate #### bytes) in file.php on line 123

                  增加限制

                  如果您知道自己在做什么并想增加限制,请参阅memory_limit:

                  ini_set('memory_limit', '16M');
                  ini_set('memory_limit', -1); // no limit
                  

                  当心!您可能只是在解决症状,而不是问题!

                  Beware! You may only be solving the symptom and not the problem!

                  错误消息指向我认为正在泄漏或不必要地累积内存的带有循环的行.我在每次迭代结束时打印了 memory_get_usage() 语句,可以看到数字缓慢增长直到达到限制:

                  The error message points to a line withing a loop that I believe to be leaking, or needlessly-accumulating, memory. I've printed memory_get_usage() statements at the end of each iteration and can see the number slowly grow until it reaches the limit:

                  foreach ($users as $user) {
                      $task = new Task;
                      $task->run($user);
                      unset($task); // Free the variable in an attempt to recover memory
                      print memory_get_usage(true); // increases over time
                  }
                  

                  出于这个问题的目的,让我们假设可以想象的最糟糕的意大利面条式代码隐藏在全局范围内的$userTask 中.

                  For the purposes of this question let's assume the worst spaghetti code imaginable is hiding in global-scope somewhere in $user or Task.

                  哪些工具、PHP 技巧或调试伏都教可以帮助我找到并解决问题?

                  推荐答案

                  PHP 没有垃圾收集器.它使用引用计数来管理内存.因此,最常见的内存泄漏源是循环引用和全局变量.如果您使用一个框架,恐怕您将有很多代码需要搜索才能找到它.最简单的方法是有选择地调用 memory_get_usage 并将其缩小到代码泄漏的位置.您还可以使用 xdebug 来创建代码跟踪.使用 执行跟踪 和 show_mem_delta 运行代码.

                  PHP doesn't have a garbage collector. It uses reference counting to manage memory. Thus, the most common source of memory leaks are cyclic references and global variables. If you use a framework, you'll have a lot of code to trawl through to find it, I'm afraid. The simplest instrument is to selectively place calls to memory_get_usage and narrow it down to where the code leaks. You can also use xdebug to create a trace of the code. Run the code with execution traces and show_mem_delta.

                  这篇关于诊断内存泄漏 - 已用完 # 字节的允许内存大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  DeepL的翻译效果还是很强大的,如果我们要用php实现DeepL翻译调用,该怎么办呢?以下是代码示例,希望能够帮到需要的朋友。 在这里需要注意,这个DeepL的账户和api申请比较难,不支持中国大陆申请,需要拥有香港或者海外信用卡才行,没账号的话,目前某宝可以
                  PHP通过phpspreadsheet导入Excel日期,导入系统后,全部变为了4开头的几位数字,这是为什么呢?原因很简单,将Excel的时间设置问文本,我们就能看到该日期本来的数值,上图对应的数值为: 要怎么解决呢?进行数据转换就行,这里可以封装方法,或者用第三方的
                  mediatemple - can#39;t send email using codeigniter(mediatemple - 无法使用 codeigniter 发送电子邮件)
                  Laravel Gmail Configuration Error(Laravel Gmail 配置错误)
                  Problem with using PHPMailer for SMTP(将 PHPMailer 用于 SMTP 的问题)
                  Issue on how to setup SMTP using PHPMailer in GoDaddy server(关于如何在 GoDaddy 服务器中使用 PHPMailer 设置 SMTP 的问题)
                • <i id='XMk9q'><tr id='XMk9q'><dt id='XMk9q'><q id='XMk9q'><span id='XMk9q'><b id='XMk9q'><form id='XMk9q'><ins id='XMk9q'></ins><ul id='XMk9q'></ul><sub id='XMk9q'></sub></form><legend id='XMk9q'></legend><bdo id='XMk9q'><pre id='XMk9q'><center id='XMk9q'></center></pre></bdo></b><th id='XMk9q'></th></span></q></dt></tr></i><div id='XMk9q'><tfoot id='XMk9q'></tfoot><dl id='XMk9q'><fieldset id='XMk9q'></fieldset></dl></div>

                    <tbody id='XMk9q'></tbody>

                    • <legend id='XMk9q'><style id='XMk9q'><dir id='XMk9q'><q id='XMk9q'></q></dir></style></legend>

                        • <small id='XMk9q'></small><noframes id='XMk9q'>

                          <tfoot id='XMk9q'></tfoot>
                            <bdo id='XMk9q'></bdo><ul id='XMk9q'></ul>