简体   繁体   English

PHP Chilkat imap 组件内存泄漏

[英]PHP Chilkat imap component memory leaking

Given:鉴于:

  1. ubuntu 18.04 Ubuntu 18.04
  2. PHP 7.2.2 (cli) (built: May 12 2019 14:29:04) ( ZTS ) PHP 7.2.2 (cli)(构建时间:2019 年 5 月 12 日 14:29:04)(ZTS)
  3. Chilkat component 9.5.0.78 Chilkat 组件 9.5.0.78

Session log is disabled.会话日志被禁用。

Script running permanently, connection is via ssh and keep opened.脚本永久运行,通过 ssh 连接并保持打开状态。

The following function called periodically:定期调用以下函数:

protected function fetchSingle(int $uid)
{
    $e = $this->imap->fetchSingleAsMime($uid, true);
}

It is just to demonstrate, that RES and %MEM on linux top keep increasing:只是为了证明,linux top 上的 RES 和 %MEM 不断增加:

在此处输入图片说明

And very important moment:非常重要的时刻:

after fetching several big emails if there is executed then next code:在获取几封大电子邮件后,如果执行了接下来的代码:

$this->imap = null;
unset($this->imap);
sleep(324);

Then RES and %MEM go down to initial values!然后 RES 和 %MEM 下降到初始值!

But without但是没有

$this->imap = null;
unset($this->imap);

RES and %MEM stay on high values! RES 和 %MEM 保持高值!

Logically I may predict that problem inside imap CkImap object...从逻辑上讲,我可以预测 imap CkImap 对象内的问题......

What can I do ?我能做什么 ? Unset periodically CkImap object and reconnect is not good solution...定期取消设置 CkImap 对象并重新连接不是好的解决方案......

Why is it so ?为什么会这样? Maybe chilkat is storing data somewhere in itself ?也许 chilkat 将数据存储在某个地方? And I should call some method to clear it ?我应该调用一些方法来清除它吗?

Reproducible code:可重现的代码:

<?php

require "core/Chilkat.php";

$ckGlobal = new CkGlobal();

$ckGlobal->UnlockBundle('XXXX');

$imap = new CkImap();
$imap->put_Utf8(true);
$imap->put_Ssl(true);
$imap->put_Port(993);
$imap->put_PeekMode(true);

$imap->Connect('imap');

$imap->Login('login', 'password');

$imap->SelectMailbox('Inbox');

// UID of last message
preg_match('/UID (\d+)/', $imap->sendRawCommand("FETCH * (UID)"), $result);


$i = 0;
while(true){
    var_dump('FETCHING');
    $mime = $imap->fetchSingleAsMime($result[1], true);
    var_dump('SLEEP');
    sleep(5);
    if(++$i >= 5) {
        var_dump('UNSET');
        $imap = null;
        unset($imap);
        sleep(666);
    }
}

With the above code we fetch email each 5 seconds and RAM consumption is increasing unstoppable.使用上面的代码,我们每 5 秒获取一次电子邮件,并且 RAM 消耗越来越大,不可阻挡。 But it must not, because we overwrite the $mime variable.但它不能,因为我们覆盖了 $mime 变量。 And once imap is unset - RAM goes down to first value.一旦 imap 未设置 - RAM 将下降到第一个值。

get_VerboseLogging - this is false by default. get_VerboseLogging - 默认情况下为 false。 And Peek mode I also tried to set to false.而 Peek 模式我也尝试设置为 false。 Nothing helped to solve or figure out the problem.没有任何帮助来解决或找出问题。

Even after $imap->Disconnect();即使在$imap->Disconnect(); RAM will not be decreased.. RAM不会减少..

When it stays at about the same utilization level, just ignore it and add more RAM ...but when it keeps growing, then you'll have to periodically purge the leakage.当它保持在大致相同的利用率水平时,只需忽略它并添加更多内存......但是当它不断增长时,您将不得不定期清除泄漏。 With closed source you can only complain at the vendor, who might also have established best practices for using their library.对于封闭源代码,您只能向供应商抱怨,他们也可能已经建立了使用其库的最佳实践。

According to Chilkat_9_5_0.Imap , there is a property VerboseLogging根据Chilkat_9_5_0.Imap ,有一个属性VerboseLogging

... and also property PeekMode might affect the memory utilization. ...还有属性PeekMode可能会影响内存利用率。

I apologize!我道歉! I have checked this code more carefully and seems RAM increased until specific limit!我更仔细地检查了这段代码,似乎 RAM 增加到特定限制! But still interesting why it is increasing..但仍然很有趣,为什么它会增加..

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM