简体   繁体   English

如何在PHP请求之间存储或共享实时数据?

[英]How to store or share live data between PHP Requests?

I want to start a project for facebook and the application will be like real-time multiplayer chess game. 我想为Facebook启动一个项目,该应用程序将类似于实时多人国际象棋游戏。 The problem I'm having is I have no idea how to store the data when a player moves one piece and update the new position in player2 browser. 我遇到的问题是我不知道当玩家移动一件时如何存储数据并在player2浏览器中更新新位置。 I'm gonna use PHP, MySQL for server side and jQuery for Client Rendering. 我将使用PHP,MySQL作为服务器端以及jQuery作为Client Rendering。 The simplest idea is to store the data in XML or MySQL and re-generate the result to player2 browser. 最简单的想法是将数据存储在XML或MySQL中,然后将结果重新生成到player2浏览器。 But I know that when thousand of players are playing, it will not be an efficient way. 但我知道,当成千上万的玩家在玩时,这不是一种有效的方法。 Since I don't have time to study new language for this project, I'm gonna have to stick with PHP. 由于我没有时间研究这个项目的新语言,因此我不得不坚持使用PHP。 I'm not going to use flash either because I want my client side light-weight and flash-free. 我也不会使用Flash,因为我希望客户端轻巧,无闪光灯。 So is there any way that will solve my problems? 那么有什么办法可以解决我的问题呢?

you would have to be polling server for update every.. maybe 2 seconds, depends on server load. 您将不得不轮询服务器以进行更新。可能需要2秒钟,具体取决于服务器负载。 If you used flash, there would be another option - to use sockets, it's much more suitable for multiplayer games, but i don't think you could make it without some third-party runtime.. HTML5 has some kind of websockets, but it's very bad when it comes to cross-browser compatibility 如果您使用Flash,则还有另一种选择-使用套接字,它更适合多人游戏,但我认为没有一些第三方运行时就无法实现。HTML5具有某种websocket,但它跨浏览器兼容性非常差

I guess going through a server is your only option. 我想通过服务器是您唯一的选择。 That is to store the game status is xml or a sql db. 也就是说要存储的游戏状态是xml还是sql db。 And than the clients need to frequently poll this status, eg by jquery ajax. 并且客户端需要频繁地轮询此状态,例如通过jquery ajax。 Having the clients to communicate directly p2p is not possible with standard web components. 使用标准Web组件无法使客户端直接进行p2p通信。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM