zhoudw
2021-12-21 6f73a8496ee81f5d708cae320e8deea37fdc562e
ws_server.php
@@ -21,21 +21,25 @@
        $this->redis_config  = $config['redis'];
        $this->server = new Swoole\WebSocket\Server($this->server_config['host'], $this->server_config['port']); // swoole连接
        // $this->server->set([
        //     'task_worker_num'       => 8,
        //     'enable_coroutine'      => true,
        //     'task_enable_coroutine' => true
        // ]);
        if (!$this->redis) {
            $this->redis = new Redis();
            $this->redis->connect($this->redis_config['host'],$this->redis_config['port'] );
            $host  = $this->server_config['allow_ip'];
            $keyList = $this->redis->keys("*{$host}*");
            foreach ($keyList as $key => $value) {
                $this->redis->del($value);
        $this->server->set([
            // 'task_worker_num'       => 8,
            // 'enable_coroutine'      => true,
            // 'task_enable_coroutine' => true,
            'max_conn'              => 100000,
        ]);
        $this->server->on('WorkerStart', function (Swoole\WebSocket\Server $server) {
            if (!$this->redis) {
                $this->redis = new Redis();
                $this->redis->connect($this->redis_config['host'],$this->redis_config['port'] );
                $host  = $this->server_config['allow_ip'];
                $keyList = $this->redis->keys("*{$host}*");
                foreach ($keyList as $key => $value) {
                    $this->redis->del($value);
                }
                $this->redis->del("{$host}*");
                $this->redis->close();
            }
            $this->redis->close();
        }
        });
        $this->server->on('start', function (Swoole\WebSocket\Server $server) {
            echo "Websocket Server is started at ws://".$this->server_config['host'].":".$this->server_config['port']."\n";
        });
@@ -230,6 +234,7 @@
    function log($title,$folder,$finename,$msg)
    {
        return;
        $logs = json_encode($msg);
        $msg = "[".date('Y-m-d H:i:s')."]\t- INFO - ".$title." - ".$logs."\n";
        //判断目的文件夹是否存在? 如果不存在就生成