1

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.

Community
  • 1
  • 1
Arkross
  • 193
  • 2
  • 10
  • I was wondering the same a while ago. I believe the problem is not in PHP, but in Apache. Lighttpd behaves much better with comet than apache. Search stackoverflow, there are a few good discussions about it. Example: http://stackoverflow.com/questions/603201/using-comet-with-php – ZolaKt Oct 07 '11 at 07:44
  • I've come across that thread, too, and many related threads in StackOverflow. The problem is I'm limited to apache within my shared web hosting. So I'm looking for the best solution I can get, given my condition above. Maybe I can make use of Perl or Python to slightly increase the performance. But anyway, thanks for the fast response, @ZolaKt :D – Arkross Oct 07 '11 at 08:18
  • I know its not what you are looking for, but generally you could do it without long-polling. With or without it, if you still have to periodically check the database, that will be the bottleneck. Only thing you get with long-polling is lesser number of requests, which will result in lower performance, but still, I think it is irrelevant if the db query takes more time than to make a request (which is probably always... some benchmarking would be nice, but haven't found anything useful) – ZolaKt Oct 07 '11 at 11:21

2 Answers2

2

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.

leggetter
  • 14,640
  • 1
  • 50
  • 58
0

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.

Ernestas Stankevičius
  • 2,484
  • 1
  • 20
  • 29
  • By "normal hosting", do you mean Virtual Private Server (VPS)? I think this is a good solution when the app grows real big and needs to handle even more connections, because I can configure the server itself. I'm familiar with Java, too. Thanks for the idea, @ernestas! – Arkross Oct 07 '11 at 11:25