I'm trying to make a multiplayer game but am a newbie to server side programming except that I know a little PHP. I learnt about this technique called long polling where the server can wait for fresh data to be available and then send it. How does one do long polling using PHP? Are there any libraries available. I'm already using ZendAMF, so how do I make zendamf and long-polling to co-exist?
While you can, theoretically, write the server-side application to use the common request lifecycle (request -> processing -> response -> stop) fronted by a HTTP server, like you would would with a website, this approach tends not to be practically feasible for most games.
When writing a game, you will probably want to look into a shared everything design, as opposed to the shared nothing, stateless design used for a webpage. The reason for this is that you will want to be able to scale to a number of concurrent users for any given session (a match in Counter Strike, for example) where the game logic depends on a shared state.
Running one instance of PHP for every user will tie up a lot of resources, as well as force you to push the game state outside of the PHP process, neither of which goes very well with either scalability or performance.
Your best bet is likely to write a stateful, event-based application that is then run in PHP deamon mode. You would bypass the web server, and deal with network programming directly.
On the client side (I do not have any experience using ZendAMF), you simply make a call with a very long timeout value, and as soon as you get a response, you make another call with another long timeout. The "long-polling" happens on the server.
On the server long-polling simply means that when your client application makes a "get" (or "post") to a PHP page, that page simply does not
exit(); until there is data to be sent. So a short loop that continually checks the status of the data until it has changed. The loop that checks data will "block" until there is data.
There maybe libraries available that help with this, but it shouldn't be necessary unless your situation is quite complex.