Realtime on your website in minutes

During development of the game we were faced with the need to ensure maximum rialtajm data exchange between users, which has led to experiments with different comet libraries.
First bike was built by dklab realplexor, who, in yet another attempt to use it, as expected, the us has brought. Can we have the hand curves, but the events without delay in 10/5/1510-15 seconds we have, unfortunately, did not work.
Dancing with a tambourine lasted a long time, and as a result we decided to stop at nginx_http_push_module, and the time spent is worth it.
The main problems encountered when working with this module:
1. Disabled the cache incurs loss events (cycle of 250 passes issued to the client only 3 event).
2. Included the cache implies a recursive get latest event.
You can select only from the inability to send messages to multiple channels simultaneously, at the level of the library itself, that is, in realplexor, as well as the lack of storing several events entering the channel, in a short period of time (time rekonekta).
A bit of âgugla helped find a JS function which, at first glance, solved the problem:

 

 

 

A little dancing with tambourines made it clear that it has its skeletons in the closet:
1. If the client has multiple events, and immediately after that the page14.04.2006 VELCOM is they will come to you again (from the cache).
2. If the tab has been inactive for a long time rekvest died, and no longer processed prior to the refreša page.
The first problem is resolved fairly simply by replacing the
var e = 0, lastModified = 0;
on
var e = 0:
LastModified = LOAD_TIME;
where LOAD_TIME asked constant in the index, as
var LOAD_TIME = <? = date (‘ r);?>”;
The second problem, I was hoping to solve will be as easy to replace
timeout: 1000 * 60 * 60 * 24
on
timeout: 1000 * 20
creating a forced rekonekt to nginx every x seconds (in our case the optimum interval is 20 seconds).
But starting the test, got even more conflicts than it was before-after the rekonektov began a hellish flood events. Thanks for the clarification of the situation, the console. The problem was that when the kverik did rekonekt, the complete handler continued to update the data on hederam, the following query would go out with If-None-Match and IfModified-Since nothing.
In the end, got the most stable function:

 

 

The call handler events looks something like this:

 

 

As in the examples on the site there is no code module, which could send soobeŝenie to multiple channels, we decided to write its function.
Implementation in php:

 

 

With the installation of Dklab Realplexor, no problems arose and the complete documentation is available on the website (http://dklab.ru/lib/dklab_realplexor) developer.
However, since nginx_http_push_module is not so easy, to be honest, on CentOS ready package that includes this module could not be found, so collect everything from source.
So let’s begin:
Create a directory where you will download all necessary elements

 

Download the latest source code from githaba:

 

Download the latest version of nginx, nginx, in this case1.1.15

 

Download additional libraries:

 

Extract the files:

Go to the folder with the source nginx’a

 

And configure nginx

 

Then

 

Now let’s create the file/etc/init.d/nginx

 

and assuming there such a script:

 

 

And now

 

Everything. the installation of nginx is complete and you can start the service nginx’a

 

Now move on to the settings:
/publisher — used for entry to the channel and must be available only to your server, or write to it to anyone.

 

/listener is available to all and serves to distribute messages to subscribers of the channel.

 

On the configure everything. Solution to all good, but we‘re having trouble configuring the crossdomainajax and module in the main branch, jsonp support, at this point, no. BUT, this fork was found functional (https://github.com/Kronuz/nginx_http_push_module). It does not differ from the original.
To enable support for jsonp location section in the/listener you want to add

 

Now, in the case of a transfer in the callback parameter data, the module will wrap the data in jsonp.