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

workerman的內(nèi)存一直增長,求解決

wangqiang
<?php

namespace Home\Controller;

use Workerman\Worker;
use Think\Controller;
use Workerman\Connection\AsyncTcpConnection;

require_once APP_PATH . 'Workerman/Autoloader.php';

class WorkermanController extends Controller
{
    public $clientGateway = array();

    public $gatewayClients = array();

    public $uidConnections = array();

    public function index()
    {
        if (!IS_CLI) {
            die("access illegal");
        }
        Worker::$daemonize = true;//以守護(hù)進(jìn)程運(yùn)行
        Worker::$pidFile = APP_PATH . '/workerman.pid';//方便監(jiān)控WorkerMan進(jìn)程狀態(tài)
        Worker::$stdoutFile = APP_PATH . '/stdout.log';//輸出日志, 如echo,var_dump等
        Worker::$logFile = APP_PATH . '/workerman.log';//workerman自身相關(guān)的日志,包括啟動(dòng)、停止等,不包含任何業(yè)務(wù)日志
        $worker = new Worker('websocket://0.0.0.0:2345');//此處我使用內(nèi)網(wǎng)ip
        $worker->name = 'weiChatWorker';
        $worker->onConnect = function ($con) {
            global $uidConnections;
            $uidConnections = $con;
        };

        $worker->onWorkerStart = function ($worker) {

            $con = new AsyncTcpConnection('xxxxxxxxxxxxxxxx');

            // 設(shè)置以ssl加密方式訪問,使之成為wss
            $con->transport = 'ssl';

            $con->onConnect = function ($con) {
                echo "tcp connect success\n";
            };

            $con->onMessage = function ($con, $data) {
                self::receiveController($data);
            };

            $con->connect();
            echo "Worker starting...\n";
        };

        $worker->onMessage = function ($connection, $data) {
            global $gatewayClients, $clientGateway;
            $postData = json_decode($data);
            $cmd = $postData->cmd;
            $gateway = $postData->bindGateway;
            if ($cmd == "01") {
                $gwArray = explode(",", $gateway);
                //        初始化客戶端綁定的網(wǎng)關(guān)
                $id = $connection->id;
                $clientGateway = $gwArray;
                foreach ($gwArray as $key) {
                    $temp = $gatewayClients;
                    if ($temp == null) {
                        $temp = array();
                    }
                    array_push($temp, $id);
                    $gatewayClients = $temp;
                }
            }
        };

        $worker->onBufferFull = function ($connection) {
            echo "bufferFull and do not send again\n";
        };
        $worker->onBufferDrain = function ($connection) {
            echo "buffer drain and continue send\n";
        };
        $worker->onWorkerStop = function ($worker) {
            echo "Worker stopping...\n";
        };
        $worker->onError = function ($connection, $code, $msg) {
            self::clearClient($connection);
            echo "error $code $msg\n";
        };

        $worker->onClose = function ($connection) {
            self::clearClient($connection);
            echo "connection closed\n";
        };
        // 運(yùn)行worker
        Worker::runAll();
    }

    function clearClient($connection)
    {
        global $gatewayClients, $clientGateway, $uidConnections;
        $id = $connection->id;
        $allGateway = $clientGateway;
        foreach ($allGateway as $item) {
//            獲取網(wǎng)關(guān)的所有client
            $allClient = $gatewayClients;
            unset($gatewayClients);
        }
        unset($clientGateway);
        unset($uidConnections);
    }

    /**
     * 接收OMS消息的處理類
     * @param $data
     */
    function receiveController($data)
    {
        global $gatewayClients, $uidConnections;
        echo $data . "\n";
        $tempData = json_decode($data);
        $cmd = $tempData->cmd;
        if ($cmd == "13") {
//            處理設(shè)備告警
//{"cmd":"13","gwID":"4612C9ECDED6","devID":"A1","type":"02","ep":"14","epData":"1","epType":"02","time":"1487061135651","amqpResource":"v1"}
            foreach ($gatewayClients as $cons) {
                $uidConnections->send($data);
            }
        }
    }
}
8744 2 0
2個(gè)回答

wangqiang

worker_name exit_status exit_count
weiChatWorker 65280 1
---------------------------------------PROCESS STATUS-------------------------------------------
pid memory listening worker_name connections total_request send_fail throw_exception
32101 55.5M websocket://0.0.0.0:2345 weiChatWorker 2 169810 0 0

  • 暫無評論
walkor 打賞

workerman本身非常穩(wěn)定,沒用內(nèi)存泄漏。目前總結(jié)內(nèi)存占用越來越高一般是以下原因?qū)е碌摹?br /> 1、業(yè)務(wù)代碼問題,比如使用了全局變量數(shù)組或者類的某個(gè)屬性是數(shù)組,數(shù)組中的元素個(gè)數(shù)一直在增加,導(dǎo)致內(nèi)存占用越來越大
2、使用了某些質(zhì)量有問題的php類庫,類庫里面同樣因?yàn)?的問題導(dǎo)致內(nèi)存不斷增長
3、某個(gè)擴(kuò)展bug導(dǎo)致。有些擴(kuò)展在使用過程中內(nèi)存會(huì)不斷增大。(這種情況比較少見)

你的可能是問題1導(dǎo)致的,
客戶端全部關(guān)閉后 打印下 $gatewayClients, $clientGateway, $uidConnections ,
看看是否有元素未刪除導(dǎo)致內(nèi)存泄漏。或者檢查下是否有其它地方使用全局?jǐn)?shù)組,沒有及時(shí)清理導(dǎo)致內(nèi)存泄漏。

  • wangqiang 2017-02-15

    total_request 的增長是AsyncTcpConnection鏈接接受的數(shù)據(jù),處理的業(yè)務(wù)邏輯中沒有向全局變量添加元素只是取數(shù)據(jù),這邊應(yīng)該不會(huì)有內(nèi)存泄漏。

  • walkor 2017-02-15

    $worker->onConnect 時(shí)有向全局?jǐn)?shù)組添加元素吧

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