Problems with socket data storage

Source: Internet
Author: User
Currently using HTML5 WebSocket and PHP to achieve a socket connection, ready to do a long-connected game,
Ready to make a server to support 100 players around (go online and try to increase the number of people), a room/game 5-8.

Now there is a question as to where the current game data exists. (game result data will be stored in the database, mainly in the middle of the game data storage)
Global variables:
stored in global variables can certainly be achieved, performance is the best,
But if the process hangs, the current number of game data disappears, and all players have to start over from the game hall again.
Redis
Redis is relatively secure, the process is hung, the player should be able to continue the game after the process restarts,
But the performance is certainly worse than the global variable, do not know whether it is necessary to design.
(currently only ready to rent a server, do not know if Redis will not hang together)

The main is not know the probability of the process hangs out how much, there is the use of Redis on the performance of the impact of how much.
Is there any prior experience in this aspect that has been taught in this area?


Reply to discussion (solution)

Look forward to the landlord experience.

No one answered, thinking of a compromise solution:
Game first with the global variable implementation, Redis as anti-hang extension function, the game on-line confirmed that the server will hang, it is necessary to implement again.
Implementation method:
1. Synchronization scheme: Separate the data needed for each room's restoration into a single Redis field (named ' Room_ '). $roomId)
2. Sync time: 1. Initial information is stored at the beginning of the Game 2. Clear information at the end of the Game 3. The game holds data once per round
3. Restore scenario: After the process starts, read the Redis room data into global variables.
Anyway, let's start with global variables ...

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.