国产+高潮+在线,国产 av 仑乱内谢,www国产亚洲精品久久,51国产偷自视频区视频,成人午夜精品网站在线观看

守護(hù)進(jìn)程無法內(nèi)存回收?

supereric

我在一個定時器中執(zhí)行函數(shù)類似下圖
[attach]1811[/attach]
?
然后內(nèi)存會一直蹭蹭往上漲(循環(huán)1000次是為了模擬超長時間下運(yùn)行)
?
剛開始是這樣,內(nèi)存占用情況
[attach]1812[/attach]
?
運(yùn)行一段時間后,變成了這樣
[attach]1813[/attach]
?
只要一直不斷運(yùn)行下去,內(nèi)存就會無限漲下去直到出現(xiàn)了錯誤提示
[attach]1814[/attach]
?
msg_send() 函數(shù)內(nèi)部大概這樣,下面就沒什么了,就是個發(fā)送的循環(huán)
[attach]1815[/attach]
?
我的問題是,執(zhí)行函數(shù)的時候產(chǎn)生的內(nèi)存消耗是沒有回收的嗎?只能讓它運(yùn)行到爆炸了?
這個問題我搜了好久,大致都是說php會自動回收內(nèi)存,但是需要腳本運(yùn)行結(jié)束后觸發(fā)回收
可是我是常駐內(nèi)存的,如何定義為腳本結(jié)束呢?
?
在實際案例中已經(jīng)產(chǎn)生的問題,特此用這種極端測試法重現(xiàn)效果。
?

5473 2 0
2個回答

supereric

問題解決啦!不是workerman的問題!
我把源代碼下載下來后按案例去做了一便,同樣的執(zhí)行代碼

<?php
use Workerman\Worker;
require_once './Workerman/Autoloader.php';
class se{
    public $worker;
    public function __construct(){
        $this->worker = new Worker("http://0.0.0.0:2345");
        $this->worker->count = 1;
        $fn = ;
        foreach ($fn as $event) {
            if (method_exists($this, $event)) {
                $this->worker->$event = ;
            }
        }

        Worker::runAll();
    }
    public function onWorkerStart(){
        \Workerman\Lib\Timer::add(1, function(){
            for($i = 0;$i < 1000;$i++){
                    $this->msg_send();
            }
        });
    }
    public function msg_send($type = 'sys',$content = '',$data = []){
        $info    = $type;
        $info    = time();
        $info = $content;
        $info  = $data;
    }
}

new se();

發(fā)現(xiàn)根本不是workerman問題,更不是程序問題,是我整合的thinkphp3.2.3出了問題![attach]1816[/attach]
?
感謝這篇文章的博主,幫我解決了這個問題
https://blog.csdn.net/qq1509334304/article/details/82775414
根據(jù)他的修改方案
找到Log.class.php修改以下函數(shù),照著這個改

static function record($message,$level=self::ERR,$record=false) {
    if($record || false !== strpos(C('LOG_LEVEL'),$level)) {
        self::$log[] =   "{$level}: {$message}\r\n";

        if(count(self::$log) > 100){
            self::save();
            self::$log = [];
        }

    }

}

便可以解決問題啦!

  • 暫無評論
yongdao35

學(xué)習(xí)了

  • 暫無評論
年代過于久遠(yuǎn),無法發(fā)表回答
??