zhoudw
2021-12-21 78c4660c12b894b9685176b585184e2d998d4324
ws_server.php
@@ -24,11 +24,22 @@
        $this->server->set([
            'task_worker_num'       => 8,
            'enable_coroutine'      => true,
            'task_enable_coroutine' => true
            'task_enable_coroutine' => true,
            'max_conn'              => 100000,
        ]);
        if (!$this->redis) {
            $this->redis = new Redis();
        }
        $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->server->on('start', function (Swoole\WebSocket\Server $server) {
            echo "Websocket Server is started at ws://".$this->server_config['host'].":".$this->server_config['port']."\n";
        });
@@ -223,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";
        //判断目的文件夹是否存在? 如果不存在就生成