socket数据存储方面的问题
目前用html5的websocket和php实现了socket连接,准备做个长连接的游戏,
准备做成一个服务器支持100玩家左右(上线后再尝试增加人数),一个房间/一局游戏5-8人。
现在有一个问题,当前游戏数据存在哪里好呢。(游戏结果数据会存到数据库,主要是游戏中间数据存哪)
全局变量:
存储在全局变量肯定可以实现的,性能是最好的,
但如果进程挂了,当前的游戏数据数就全部消失了,所有玩家都都得从游戏大厅重新开始
redis:
存redis是比较安全,进程挂了的话进程重启后玩家应该能继续该局游戏,
但是性能上肯定比全局变量差,不知道有没有必要这么设计。
(目前只准备租一个服务器,不知道redis会不会一起挂掉)
主要是不知道进程挂掉的概率有多大,还有使用redis对性能的影响有多大。
有没有之前做过这方面功能的传授一下这方面的经验。
回复讨论(解决方案)
期待楼主经验。
没人回答,自己想了个折中的方案:
游戏先用全局变量实现,redis作为防挂扩展功能,游戏上线后确认了服务器会挂,确实有必要后再实现。
实现方式:
1.同步方案:将每个房间的还原需要的数据单独拼接在一起,单独存入redis一个字段(名为 'room_'.$roomId)
2.同步时间:1.游戏开始时存放初始信息 2.游戏结束时清除信息 3.游戏每进行一个回合存放一次数据
3.还原方案:进程启动后,读取redis各房间数据存入全局变量。
总之现在先用全局变量实现再说...

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



Alipay PHP...

JWT is an open standard based on JSON, used to securely transmit information between parties, mainly for identity authentication and information exchange. 1. JWT consists of three parts: Header, Payload and Signature. 2. The working principle of JWT includes three steps: generating JWT, verifying JWT and parsing Payload. 3. When using JWT for authentication in PHP, JWT can be generated and verified, and user role and permission information can be included in advanced usage. 4. Common errors include signature verification failure, token expiration, and payload oversized. Debugging skills include using debugging tools and logging. 5. Performance optimization and best practices include using appropriate signature algorithms, setting validity periods reasonably,

Article discusses late static binding (LSB) in PHP, introduced in PHP 5.3, allowing runtime resolution of static method calls for more flexible inheritance.Main issue: LSB vs. traditional polymorphism; LSB's practical applications and potential perfo

Article discusses essential security features in frameworks to protect against vulnerabilities, including input validation, authentication, and regular updates.

The article discusses adding custom functionality to frameworks, focusing on understanding architecture, identifying extension points, and best practices for integration and debugging.

The application of SOLID principle in PHP development includes: 1. Single responsibility principle (SRP): Each class is responsible for only one function. 2. Open and close principle (OCP): Changes are achieved through extension rather than modification. 3. Lisch's Substitution Principle (LSP): Subclasses can replace base classes without affecting program accuracy. 4. Interface isolation principle (ISP): Use fine-grained interfaces to avoid dependencies and unused methods. 5. Dependency inversion principle (DIP): High and low-level modules rely on abstraction and are implemented through dependency injection.

Sending JSON data using PHP's cURL library In PHP development, it is often necessary to interact with external APIs. One of the common ways is to use cURL library to send POST�...

How to automatically set the permissions of unixsocket after the system restarts. Every time the system restarts, we need to execute the following command to modify the permissions of unixsocket: sudo...
