Flash 问答游戏与 "php & http请求” VS“套接字服务器”
我想构建一个带有房间和聊天功能的问答游戏。是否可以仅使用 PHP 和 HTTP 请求来实现?根据您的经验,它能容纳多少游客。我知道使用套接字服务器更好,但我现在只有一个共享主机。
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
我想构建一个带有房间和聊天功能的问答游戏。是否可以仅使用 PHP 和 HTTP 请求来实现?根据您的经验,它能容纳多少游客。我知道使用套接字服务器更好,但我现在只有一个共享主机。
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
接受
或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
发布评论
评论(1)
当然,仅使用 PHP+HTTP 就可以实现。不过,如果有新的聊天或游戏动作,您必须在
setInterval
上运行一个轮询器,以便通过XMLHttpRequest
不断询问服务器。您可以支持多少用户取决于更新时间必须有多快;如果用户可以在轮询之间等待很多秒,那么您就不会有问题,但如果他们需要瞬间更新,则需要进行大量轮询,而您的共享服务器根本不够用。对于任何实时响应式聊天或动作游戏,您需要自己的“套接字服务器”类型的安排,使用“Comet' 式的长轮询技术、Flash 套接字,或者将来的 HTML5 更方便的 WebSocket。
(无论如何,我都会考虑虚拟专用服务器;现在它们很便宜,并且共享 PHP 脚本服务器会让您在性能和安全性方面受到其他用户的摆布。)
Sure it's possible with only PHP+HTTP. You'd have to have a poller running on a
setInterval
to keep asking the server viaXMLHttpRequest
if there are new lines of chat or game moves, though. How many users you can support depends on how quick that update time must be; if users can wait many seconds between polls you won't have a problem, but if they need split-second updates that's a lot of polling and your shared server won't be sufficient at all.For any realtime responsive chat or action games you would need your own ‘socket server’ type of arrangement, using ‘Comet’-style long-polling techniques, Flash sockets or, in the future, HTML5's much more convenient WebSocket.
(I'd look at virtual dedicated servers anyway; they're cheap these days and sharing a server for PHP scripts puts you at the mercy of other users for performance and security.)