| | |
| | | $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->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->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"; |
| | | }); |
| | |
| | | |
| | | function log($title,$folder,$finename,$msg) |
| | | { |
| | | return; |
| | | $logs = json_encode($msg); |
| | | $msg = "[".date('Y-m-d H:i:s')."]\t- INFO - ".$title." - ".$logs."\n"; |
| | | //判断目的文件夹是否存在? 如果不存在就生成 |