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

      <small id='SRuYF'></small><noframes id='SRuYF'>

      <tfoot id='SRuYF'></tfoot>

      <i id='SRuYF'><tr id='SRuYF'><dt id='SRuYF'><q id='SRuYF'><span id='SRuYF'><b id='SRuYF'><form id='SRuYF'><ins id='SRuYF'></ins><ul id='SRuYF'></ul><sub id='SRuYF'></sub></form><legend id='SRuYF'></legend><bdo id='SRuYF'><pre id='SRuYF'><center id='SRuYF'></center></pre></bdo></b><th id='SRuYF'></th></span></q></dt></tr></i><div id='SRuYF'><tfoot id='SRuYF'></tfoot><dl id='SRuYF'><fieldset id='SRuYF'></fieldset></dl></div>
    1. 脚本运行时php垃圾收集

      php garbage collection while script running(脚本运行时php垃圾收集)

      <small id='9XQ66'></small><noframes id='9XQ66'>

      <tfoot id='9XQ66'></tfoot>
          <tbody id='9XQ66'></tbody>
          • <bdo id='9XQ66'></bdo><ul id='9XQ66'></ul>
              <i id='9XQ66'><tr id='9XQ66'><dt id='9XQ66'><q id='9XQ66'><span id='9XQ66'><b id='9XQ66'><form id='9XQ66'><ins id='9XQ66'></ins><ul id='9XQ66'></ul><sub id='9XQ66'></sub></form><legend id='9XQ66'></legend><bdo id='9XQ66'><pre id='9XQ66'><center id='9XQ66'></center></pre></bdo></b><th id='9XQ66'></th></span></q></dt></tr></i><div id='9XQ66'><tfoot id='9XQ66'></tfoot><dl id='9XQ66'><fieldset id='9XQ66'></fieldset></dl></div>
              <legend id='9XQ66'><style id='9XQ66'><dir id='9XQ66'><q id='9XQ66'></q></dir></style></legend>

              • 本文介绍了脚本运行时php垃圾收集的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                我有一个在 cron 上运行的 PHP 脚本,执行时间可能长达 15 分钟.我定期让它吐出 memory_get_usage() 以便我可以看到发生了什么.它第一次告诉我我的使用量是 10 兆.当脚本完成时,我达到了 114 兆!

                I have a PHP script that runs on cron that can take up to an 15 minutes to execute. At regular intervals I have it spitting out memory_get_usage() so I can see what is happening. The first time it tells me my usage I am at 10 megs. When the script finishes I am at 114 megs!

                PHP 是否在脚本运行时进行垃圾收集?或者所有这些记忆发生了什么?我可以做些什么来强制垃圾收集.我的脚本正在执行的任务是每晚将几千个节点导入 Drupal.所以它多次做同样的事情.

                Does PHP do it's garbage collection while the script is running? Or what is happening to all that memory? Is there something I can do to force garbage collection. The task that my script is doing is a nightly import of a couple thousand nodes into Drupal. So it is doing the same thing a lot of times.

                有什么建议吗?

                推荐答案

                关键是你取消设置你的全局只要您不需要变量,就立即使用它们.

                The key is that you unset your global variables as soon as you don't need them.

                您无需为局部变量和对象属性显式调用 unset ,因为当函数超出范围或对象被销毁时,它们会被销毁.

                You needn't call unset explicitly for local variables and object properties because these are destroyed when the function goes out of scope or the object is destroyed.

                PHP 为所有变量保留一个引用计数,并在引用计数变为零时立即销毁它们(在大多数情况下).对象有一个内部引用计数,变量本身(对象引用)每个都有一个引用计数.当所有对象引用因为它们的引用计数达到 0 而被销毁时,对象本身将被销毁.示例:

                PHP keeps a reference count for all variables and destroys them (in most conditions) as soon as this reference count goes to zero. Objects have one internal reference count and the variables themselves (the object references) each have one reference count. When all the object references have been destroyed because their reference coutns have hit 0, the object itself will be destroyed. Example:

                $a = new stdclass; //$a zval refcount 1, object refcount 1
                $b = $a;           //$a/$b zval refcount 2, object refcount 1
                //this forces the zval separation because $b isn't part of the reference set:
                $c = &$a;          //$a/$c zval refcount 2 (isref), $b 1, object refcount 2
                unset($c);         //$a zval refcount 1, $b 1, object refcount 2
                unset($a);         //$b refcount 1, object refcount 1
                unset($b);         //everything is destroyed
                

                但请考虑以下场景:

                class A {
                    public $b;
                }
                class B {
                    public $a;
                }
                
                $a = new A;
                $b = new B;
                $a->b = $b;
                $b->a = $a;
                unset($a); //cannot destroy object $a because $b still references it
                unset($b); //cannot destroy object $b because $a still references it
                

                这些循环引用是 PHP 5.3 垃圾收集器发挥作用的地方.您可以使用 gc_collect_cycles 显式调用垃圾收集器.

                These cyclic references are where PHP 5.3's garbage collector kicks in. You can explicitly invoke the garbage collector with gc_collect_cycles.

                另见参考计数基础和手册中的收集周期.

                这篇关于脚本运行时php垃圾收集的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                相关文档推荐

                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 的问题)

                  <bdo id='Js9aU'></bdo><ul id='Js9aU'></ul>
                • <legend id='Js9aU'><style id='Js9aU'><dir id='Js9aU'><q id='Js9aU'></q></dir></style></legend>
                  <tfoot id='Js9aU'></tfoot>

                      <small id='Js9aU'></small><noframes id='Js9aU'>

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