The idea behind is a multiplayer browser game which interacts with a PHP server.
Right now it works like this:
Every second the browser is doing an ajax call to the php script which checks everything and returns the response.
All in all it runs fine, but the problem is that the browser gets overloaded (because of thousands of ajax requests) after a while and it becomes impossible to play anymore. Also the delay of 1+ second is pretty much.
My idea is to have a simple flash pixel which will have a 2-way communication with the server.
For example:
- User makes and action
- Javascript function calls the flash pixel with some parameters
- The flash sends the request to the server
- The server “announce” about this action to all other flash listeners (users online)
- The response from the server is received
- UI updated
Something like that.
The data which is sent and received can be just strings (json) or any other.
I read about different RTMP servers and also about smartfoxserver.com. It wouldn’t be a problem to buy any of them, but in my eyes they are offering too much for my needs (audio video streaming, etc.). Also they are not PHP based. So using an RTMP server would require it to start a PHP script when needed. This would be also not a problem until the user can play without lags.
In case the solution would be to install a RTMP server, there is a “RTMP client” in PHP, but unfortunately there isn’t much information/documentation about it.
In any case, if no solution is found, I’m going to use the same Flash “pixel” which will send requests and receive responses via PHP AMF. It will have small delays and won’t be persistent but it should solve a part of the problem.
Maybe some of you already had this problem and found a solution or any other ideas of how to realize this are welcome.
Thank you
P.S. Google Wave was using something similar in their interactive chat, when some user was typing and the other could see this in real time.
You can use XMLSocket in AS3 to establish a socket connection with the PHP server.