I've seen many games on FB have queue which connects you to an opponent you should be playing against.

So my question is: In which language can it be coded? Is it possible to do it in PHP/Javascript?

Does anyone have any real/live example or tutorial how is this done?

Thanks in advance!

1 Answer 1


You can write up a system like that in any Turing-complete language. It's really not that complicated. Here's the basic, high-level principle (for one way to do it; you can probably do it other ways):

You have a list of all people waiting for a match. (Not necessarily a List list, but some data structure that can hold multiple people.) When a new applicant shows up, check them against the list and see if you find a suitable match. If so, pull the match off the list and send each player's system a notification that they need to connect with the other system. Otherwise, add the newcomer to the list. If someone gets tired of waiting and disconnects, remove them from the list.

Details of how to implement this will obviously vary quite a bit depending on exactly what your system is doing. In the simplest case, there's no such thing as an unsuitable match, so your waiting list will never be longer than one player. At the other extreme, if your list is likely to contain thousands of players for whatever reason, you might want to look at optimizing the lookup somehow. But in the in-between territory, the technique I just described will probably work well.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.