<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垃圾收集的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                相关文档推荐

                How do I pass parameters into a PHP script through a webpage?(如何通过网页将参数传递给 PHP 脚本?)
                PHP - include a php file and also send query parameters(PHP - 包含一个 php 文件并发送查询参数)
                Where can I read about conditionals done with quot;?quot; and quot;:quot; (colon)?(我在哪里可以阅读有关使用“?完成的条件的信息?和“:(冒号)?)
                Accessing arrays whitout quoting the key(在不引用键的情况下访问数组)
                What is the name for the quot;lt;lt;lt;quot; operator?(“lt;lt;lt;的名字是什么?操作员?)
                default as first option in switch statement?(默认为 switch 语句中的第一个选项?)

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