Apache with Comet Support

让人想犯罪 __ 提交于 2019-12-29 09:24:46

问题


I'd like to build a multiplayer web game application in which it supports chat. I presume the application will have to handle hundreds of simultaneous connections.

I'm planning to host my application in a shared web hosting, which has these limitations (most likely similar to PHP + Comet (long-polling) scaling / hosts):

  • It does not seem I can change the web server. Most likely it's using Apache.
  • Supports MySQL 5, PHP 5.3.x, Perl, Python, Ruby on Rails, CGI

(To be more precise, I'll be using HawkHost's shared web hosting.)

And here are my result of research, followed by my questions:

  1. Some resources (like Python Comet Server) say that PHP is not good for handling concurrent connections, while Python is better choice. Is this true?
  2. I've tried the long polling technique in PHP (although I don't know whether it's correctly implemented or not, like Comet issue with abandoned open connections) using "Loop endlessly until the data changes." method. This almost works. The remaining problem is that the server process never dies when the browser is closed (the server does not know that the connection has been terminated, and the data never changes). Is there any way the PHP can detect whether the browser has been terminated so that it stops the loop?

I've been looking everywhere to look for answers but still I can't conclude anything. This topic has also been asked on StackOverflow so many times, I'm sorry if I may sound repeating >.<.

Currently I am able to code using PHP, MySQL, and JQuery for JS. I'm still new to the term Comet and Server Push. If necessary, I'm also willing to learn new scripting language like Python.

I appreciate any insights of what scripting language, framework, and techniques to use to start my project.


回答1:


When you have a shared hosting environment and there are a number of restrictions enforced then it's a good idea to outsource the realtime functionality. I would say this since I work for one such company, Pusher. But I hope others will back me up on this.

When using a hosted solution you can push a notification by making a HTTP request to a RESTful API. The service will then deliver the message to the connected Web Client (browser). The browser does need to include a script tag or use a library that also connects to the hosted service.

The main benefits are:

  • No installation or maintenance
  • No need to handle persistent connections - no resource usage
  • Really simple usage: Script tag in app and call REST API
  • The hosted solution handles scaling

Also, here's a list of hosted realtime solutions.




回答2:


So you can use Python. Then you can use Tornado. (psst... facebook uses it)

And I had same problem with open connections. Just don't spend time for search solution in PHP - later you will be sorry. I was. Just use what is made for Comet. If you more prefere JAVA, then there is: CometD.

And for game get a normal hosting. They cheap this days.



来源:https://stackoverflow.com/questions/7684279/apache-with-comet-support

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!