{"id":167895,"date":"2013-02-01T14:30:03","date_gmt":"2013-02-01T10:30:03","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=167895"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=167895","title":{"rendered":"<span class=\"post_title\">Long Polling \u043e\u0442 \u0410 \u0434\u043e \u042f \u0441\u0432\u043e\u0438\u043c\u0438 \u0440\u0443\u043a\u0430\u043c\u0438<\/span>"},"content":{"rendered":"<div class=\"content html_format\">   \t\u041a\u0430\u043a \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c long polling \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e Nginx \u0438 Javascript \u0432 \u0441\u0435\u0442\u0438 \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u043c\u043d\u043e\u0433\u043e \u043c\u0430\u0442\u0435\u0440\u0438\u0430\u043b\u0430. \u041d\u043e \u043f\u043e\u043b\u043d\u043e\u0433\u043e \u0440\u0443\u043a\u043e\u0432\u043e\u0434\u0441\u0442\u0432\u0430 \u044f \u0435\u0449\u0451 \u043d\u0435 \u0432\u0441\u0442\u0440\u0435\u0447\u0430\u043b. \u0422\u043e \u0432\u043e\u0437\u043d\u0438\u043a\u0430\u044e\u0442 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u044b \u0441 \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0446\u0438\u0435\u0439 \u043c\u043e\u0434\u0443\u043b\u044f \u043f\u043e\u0434 Nginx, \u0442\u043e \u0432 \u0431\u0440\u0430\u0443\u0437\u0435\u0440\u0435 \u0432\u0435\u0440\u0442\u0438\u0442\u0441\u044f \u0438\u043a\u043e\u043d\u043a\u0430 \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0438 \u043f\u0440\u0438 long poll \u0437\u0430\u043f\u0440\u043e\u0441\u0430\u0445. \u041f\u043e\u0434 \u043a\u0430\u0442\u043e\u043c, \u043f\u043e\u043b\u043d\u044b\u0439 \u043c\u0430\u0442\u0435\u0440\u0438\u0430\u043b \u043a\u0430\u043a \u0436\u0435 \u0432\u0441\u0435 \u0442\u0430\u043a\u0438 \u044d\u0442\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e.<br \/>  <a name=\"habracut\"><\/a><\/p>\n<h4>\u041a\u043e\u043c\u043f\u0438\u043b\u044f\u0446\u0438\u044f Nginx \u043c\u043e\u0434\u0443\u043b\u044f \u043f\u043e\u0434 linux<\/h4>\n<p>  \u0414\u043b\u044f \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u043a\u0438 long polling \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0439 \u0432 \u0441\u0435\u0440\u0432\u0435\u0440\u0435 Nginx, \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043d \u0437\u0430\u043c\u0435\u0447\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u0439 \u043c\u043e\u0434\u0443\u043b\u044c <a href=\"https:\/\/github.com\/wandenberg\/nginx-push-stream-module\">nginx-push-stream-module<\/a>. \u0422\u0430\u043a \u043a\u0430\u043a \u043e\u043d \u043d\u0435 \u0432\u0445\u043e\u0434\u0438\u0442 \u0432 \u043e\u0444\u0438\u0446\u0438\u0430\u043b\u044c\u043d\u0443\u044e \u043f\u043e\u0441\u0442\u0430\u0432\u043a\u0443, \u0435\u0433\u043e \u043d\u0443\u0436\u043d\u043e \u0441\u043a\u0430\u0447\u0430\u0442\u044c, \u043d\u0430\u0441\u0442\u0440\u043e\u0438\u0442\u044c \u0438 \u0441\u043a\u043e\u043c\u043f\u0438\u043b\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0432\u043c\u0435\u0441\u0442\u0435 \u0441 Nginx.<\/p>\n<p>  \u041f\u0435\u0440\u0435\u0434 \u044d\u0442\u0438\u043c \u0443 \u0432\u0430\u0441 \u0434\u043e\u043b\u0436\u043d\u044b \u0431\u044b\u0442\u044c \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043b\u0435\u043d\u044b \u0432\u0441\u0435 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u044b\u0435 \u043f\u0430\u043a\u0435\u0442\u044b  <\/p>\n<pre><code class=\"bash\">apt-get install git apt-get install make apt-get install g++ apt-get install libpcre3 libpcre3-dev libpcrecpp0 libssl-dev zlib1g-dev <\/code><\/pre>\n<p>  \u0414\u0430\u043b\u0435\u0435 \u043d\u0443\u0436\u043d\u043e \u0441\u043a\u0430\u0447\u0430\u0442\u044c \u0441\u0430\u043c \u043c\u043e\u0434\u0443\u043b\u044c nginx-push-stream-module, nginx \u0438 \u0441\u043a\u043e\u043c\u043f\u0438\u043b\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0438\u0445 \u0432\u043c\u0435\u0441\u0442\u0435.<\/p>\n<p>  \u041a\u043b\u043e\u043d\u0438\u0440\u0443\u0435\u043c \u043f\u0440\u043e\u0435\u043a\u0442 \u0438\u0437 GIT  <\/p>\n<pre><code class=\"bash\">git clone http:\/\/github.com\/wandenberg\/nginx-push-stream-module.git <\/code><\/pre>\n<p>  \u0421\u043a\u0430\u0447\u0438\u0432\u0430\u0435\u043c \u0438 \u0440\u0430\u0441\u043f\u0430\u043a\u043e\u0432\u044b\u0432\u0430\u0435\u043c \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0438\u0439 nginx  <\/p>\n<pre><code class=\"bash\">NGINX_PUSH_STREAM_MODULE_PATH=$PWD\/nginx-push-stream-module wget http:\/\/nginx.org\/download\/nginx-1.2.6.tar.gz tar xzvf nginx-1.2.6.tar.gz <\/code><\/pre>\n<p>  \u041d\u0430\u0441\u0442\u0440\u0430\u0438\u0432\u0430\u0435\u043c \u0438 \u043a\u043e\u043c\u043f\u0438\u043b\u0438\u0440\u0443\u0435\u043c nginx \u0432\u043c\u0435\u0441\u0442\u0435 \u0441 nginx-push-stream-module  <\/p>\n<pre><code class=\"bash\">cd nginx-1.2.6 .\/configure --add-module=..\/nginx-push-stream-module make make install <\/code><\/pre>\n<p>  \u0415\u0441\u043b\u0438 \u043d\u0435\u0442 \u043e\u0448\u0438\u0431\u043e\u043a \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0446\u0438\u0438, \u0432\u0441\u0435 \u0433\u043e\u0442\u043e\u0432\u043e. \u041f\u0440\u043e\u0432\u0435\u0440\u0438\u043c, \u0447\u0442\u043e \u043c\u044b \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u043b\u0438 \u0438\u043c\u0435\u043d\u043d\u043e \u0442\u043e\u0442 nginx \u0438 \u0442\u043e, \u0447\u0442\u043e \u0442\u0435\u043f\u0435\u0440\u044c \u0432 \u043d\u0435\u043c \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u0435\u0441\u0442\u044c \u043c\u043e\u0434\u0443\u043b\u044c nginx-push-stream-module  <\/p>\n<pre><code class=\"bash\">check: \/usr\/local\/nginx\/sbin\/nginx -v test configuration: \/usr\/local\/nginx\/sbin\/nginx -c $NGINX_PUSH_STREAM_MODULE_PATH\/misc\/nginx.conf -t <\/code><\/pre>\n<p>  \u041f\u043e\u0441\u043b\u0435 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u044d\u0442\u0438\u0445 \u043a\u043e\u043c\u0430\u043d\u0434, \u0432\u044b \u0434\u043e\u043b\u0436\u043d\u044b \u0443\u0432\u0438\u0434\u0435\u0442\u044c \u0442\u0430\u043a\u043e\u0435:  <\/p>\n<pre><code class=\"bash\">nginx version: nginx\/1.2.6 the configuration file $NGINX_PUSH_STREAM_MODULE_PATH\/misc\/nginx.conf syntax is ok configuration file $NGINX_PUSH_STREAM_MODULE_PATH\/misc\/nginx.conf test is successful <\/code><\/pre>\n<h4>\u041d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0430\u0439 Nginx \u0434\u043b\u044f Long Polling \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0439<\/h4>\n<p>  \u0414\u043b\u044f \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0438 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u043a\u0438 long polling, \u0432 \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u0438 Nginx, \u043d\u0443\u0436\u043d\u043e \u043f\u0440\u043e\u043f\u0438\u0441\u0430\u0442\u044c \u043a\u0430\u043a \u043c\u0438\u043d\u0438\u043c\u0443\u043c \u0434\u0432\u0430 \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u0430. \u041f\u0435\u0440\u0432\u044b\u0439 \u0434\u043b\u044f \u043f\u043e\u0434\u043f\u0438\u0441\u0447\u0438\u043a\u043e\u0432 (\u0442\u0435\u0445 \u043a\u0442\u043e \u0431\u0443\u0434\u0435\u0442 \u043f\u043e\u043b\u0443\u0447\u0430\u0442\u044c \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f), \u0432\u0442\u043e\u0440\u043e\u0439 \u0434\u043b\u044f \u043f\u0443\u0431\u043b\u0438\u043a\u0430\u0446\u0438\u0438 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0439 (\u0442\u0435\u0445 \u043a\u0442\u043e \u0431\u0443\u0434\u0435\u0442 \u043f\u043e\u0441\u044b\u043b\u0430\u0442\u044c \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f).<\/p>\n<p>  \u041e\u043f\u0443\u0441\u043a\u0430\u044f \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0443 \u043e\u0441\u0442\u0430\u043b\u044c\u043d\u044b\u0445 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u0432 \u0441\u0435\u0440\u0432\u0435\u0440\u0430, \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u043e\u043d\u043d\u044b\u0439 \u0444\u0430\u0439\u043b \/usr\/local\/nginx\/nginx.conf \u0434\u043e\u043b\u0436\u0435\u043d \u0432\u044b\u0433\u043b\u044f\u0434\u0435\u0442\u044c \u0442\u0430\u043a:  <\/p>\n<pre><code class=\"bash\">...  http {     ...      server {         listen 80;         server_name stream.example.com;         charset utf-8;          location \/pub {             push_stream_publisher admin;             set $push_stream_channel_id             $arg_id;             allow  1.1.1.1  # ip \u0430\u0434\u0440\u0435\u0441 \u0441\u0435\u0440\u0432\u0435\u0440\u0430 \u043f\u043e\u0441\u044b\u043b\u0430\u044e\u0449\u0435\u0433\u043e \u0441\u043e\u0431\u044b\u0442\u0438\u0435         }          location ~ \/sub\/(.*) {             push_stream_subscriber                  long-polling;             set $push_stream_channels_path          $1;             push_stream_last_received_message_tag   $arg_tag;             push_stream_last_received_message_time  $arg_time;             push_stream_longpolling_connection_ttl  25s;         }     } } <\/code><\/pre>\n<p>  \u0412 \u0434\u0430\u043d\u043d\u043e\u043c \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \/pub \u2014 \u0430\u0434\u0440\u0435\u0441 \u0434\u043b\u044f \u043f\u0443\u0431\u043b\u0438\u043a\u0430\u0446\u0438\u0438 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0439, \u0435\u0433\u043e \u0434\u043e\u043b\u0436\u0435\u043d \u0432\u0438\u0434\u0435\u0442\u044c \u0442\u043e\u043b\u044c\u043a\u043e \u0432\u0430\u0448 \u0441\u0435\u0440\u0432\u0435\u0440 (1.1.1.1), \u043e\u0442 \u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e \u043f\u0440\u0438\u0445\u043e\u0434\u044f\u0442 \u0441\u043e\u0431\u044b\u0442\u0438\u044f, \/sub \u2014 \u0430\u0434\u0440\u0435\u0441 \u0434\u043b\u044f \u043f\u043e\u0434\u043f\u0438\u0441\u0447\u0438\u043a\u043e\u0432, \u0442\u0435\u0445 \u043a\u043e\u043c\u0443 \u0431\u0443\u0434\u0443\u0442 \u043f\u0435\u0440\u0435\u0441\u044b\u043b\u0430\u0442\u044c\u0441\u044f \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f. \u0418\u0434\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0431\u0443\u0434\u0435\u0442 \u0438\u0434\u0435\u043d\u0442\u0438\u0444\u0438\u0446\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043f\u043e\u0434\u043f\u0438\u0441\u0447\u0438\u043a\u043e\u0432, \u043f\u0435\u0440\u0435\u0434\u0430\u0435\u0442\u0441\u044f \u043f\u043e\u0441\u043b\u0435 \/sub, \u0438 \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0435\u0442\u0441\u044f \u043a\u0430\u043a \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440 id \u0432 \/pub.<\/p>\n<p>  \u041e\u0431 \u043e\u0447\u0435\u043d\u044c \u0432\u0430\u0436\u043d\u044b\u0445 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0430\u0445 push_stream_last_received_message_tag \u0438 push_stream_last_received_message_time \u0440\u0435\u0447\u044c \u043f\u043e\u0439\u0434\u0435\u0442 \u043d\u0438\u0436\u0435, \u043a\u043e\u0433\u0434\u0430 \u043a\u043e\u0441\u043d\u0435\u043c\u0441\u044f javascript.<\/p>\n<p>  \u041f\u0440\u0438\u043c\u0435\u0440 \u0434\u043b\u044f \u043f\u043e\u043d\u0438\u043c\u0430\u043d\u0438\u044f \u0440\u0430\u0431\u043e\u0442\u044b:<br \/>  \u041c\u043e\u0436\u043d\u043e \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043f\u043e\u0434\u043f\u0438\u0441\u0447\u0438\u043a\u043e\u0432, \u0432\u044b\u0437\u0432\u0430\u0432: <a href=\"http:\/\/stream.example.com\/sub\/1\">stream.example.com\/sub\/1<\/a>, <a href=\"http:\/\/stream.example.com\/sub\/2\">stream.example.com\/sub\/2<\/a>, <a href=\"http:\/\/stream.example.com\/sub\/3\">stream.example.com\/sub\/3<\/a>. \u041a\u0430\u0436\u0434\u044b\u0439 \u0438\u0437 \u043d\u0438\u0445 \u0431\u0443\u0434\u0435\u0442 \u00ab\u0432\u0438\u0441\u0435\u0442\u044c\u00bb \u043d\u0430 Nginx \u0441\u0435\u0440\u0432\u0435\u0440\u0435 \u0432 \u0442\u0435\u0447\u0435\u043d\u0438\u0438 25 \u0441\u0435\u043a\u0443\u043d\u0434 (push_stream_longpolling_connection_ttl). \u0415\u0441\u043b\u0438 \u043c\u044b \u0432\u044b\u0437\u043e\u0432\u0435\u043c POST \u0437\u0430\u043f\u0440\u043e\u0441 \u043d\u0430 <a href=\"http:\/\/stream.example.com\/pub?id=2\">stream.example.com\/pub?id=2<\/a> \u0438 \u043f\u0435\u0440\u0435\u0434\u0430\u0434\u0438\u043c \u0432 \u0442\u0435\u043b\u0435 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435 \u00abHello\u00bb, \u0442\u043e \u043f\u043e\u0434\u043f\u0438\u0441\u0447\u0438\u043a \u00ab\u0432\u0438\u0441\u044f\u0449\u0438\u0439\u00bb \u043d\u0430 \/sub\/2, \u043f\u043e\u043b\u0443\u0447\u0438\u0442 \u043e\u0442\u0432\u0435\u0442 \u00abHello\u00bb. \u0423\u0434\u043e\u0431\u043d\u043e \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0442\u044c \u044d\u0442\u043e \u0432 \u043f\u043b\u0430\u0433\u0438\u043d\u0435 <a href=\"https:\/\/addons.mozilla.org\/ru\/firefox\/addon\/poster\">Poster<\/a> \u0434\u043b\u044f FireFox.<\/p>\n<h4>\u0421\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u043f\u043e\u0434\u043f\u0438\u0441\u0447\u0438\u043a\u043e\u0432 \u0432 Javascript<\/h4>\n<p>  \u0421\u043a\u043e\u0440\u0435\u0435 \u0432\u0441\u0435\u0433\u043e, long polling \u0432\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0434\u043b\u044f \u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u044f \u043a\u0430\u043a\u0438\u0445-\u043b\u0438\u0431\u043e \u0434\u0430\u043d\u043d\u044b\u0445 \u0432 \u0431\u0440\u0430\u0443\u0437\u0435\u0440\u0435, \u0438 \u0434\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u0432\u0430\u043c \u043f\u043e\u043d\u0430\u0434\u043e\u0431\u0438\u0442\u0441\u044f \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c Javascript \u043a\u043b\u0438\u0435\u043d\u0442\u0430.<\/p>\n<p>  \u042f \u043f\u0440\u043e\u0431\u043e\u0432\u0430\u043b \u0440\u0430\u0437\u043d\u044b\u0435 \u043c\u0435\u0442\u043e\u0434\u0430, \u043d\u043e \u0437\u0430 \u044d\u0442\u0430\u043b\u043e\u043d \u0432\u044b\u0431\u0440\u0430\u043b <a href=\"http:\/\/en.wikipedia.org\/wiki\/Cross-origin_resource_sharing\">CORS (Cross-origin resource sharing)<\/a>. \u041f\u043e \u0441\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u044e \u0441 \u0434\u0440\u0443\u0433\u0438\u043c\u0438 \u043c\u0435\u0442\u043e\u0434\u0430\u043c\u0438 \u0438\u043c\u0435\u0435\u0442 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0435 \u043f\u0440\u0435\u0438\u043c\u0443\u0449\u0435\u0441\u0442\u0432\u0430:  <\/p>\n<ul>\n<li>\u041e\u0442\u043b\u0438\u0447\u043d\u043e \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u0432\u043e \u0432\u0435\u0445 \u0431\u0440\u0430\u0443\u0437\u0435\u0440\u0430\u0445 Chrome, FireFox, Opera, IE 8, 9, 10<\/li>\n<li>\u0412 \u0431\u0440\u0430\u0443\u0437\u0435\u0440\u0430\u0445 \u043d\u0435 \u0432\u0438\u0441\u0438\u0442 \u0438\u043a\u043e\u043d\u043a\u0430 \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0438 \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u044b<\/li>\n<li>\u0420\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u043d\u0430 \u0440\u0430\u0437\u043d\u044b\u0445 \u0434\u043e\u043c\u0435\u043d\u0430\u0445 (\u043a\u0440\u043e\u0441\u0441\u0434\u043e\u043c\u0435\u043d\u043d\u043e)<\/li>\n<\/ul>\n<p>  \u041f\u0443\u0441\u043a\u0430\u0439 $ \u2014 jQuery, \u0430 \u0432 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0439 subID \u2014 \u0443\u043d\u0438\u043a\u0430\u043b\u044c\u043d\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0434\u043b\u044f \u043f\u043e\u0434\u043f\u0438\u0441\u0447\u0438\u043a\u0430  <\/p>\n<pre><code class=\"javascript\">var LongPolling = {   etag: 0,   time: null,    init: function () {     var $this = this, xhr;     if ($this.time === null) {       $this.time = $this.dateToUTCString(new Date());     }      if (window.XDomainRequest) {       \/\/ \u0415\u0441\u043b\u0438 IE, \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u043c \u0440\u0430\u0431\u043e\u0442\u0443 \u0447\u0443\u0442\u044c \u043f\u043e\u0437\u0436\u0435 (\u0438\u0437-\u0437\u0430 \u0431\u0430\u0433\u0430 IE8)       setTimeout(function () {         $this.poll_IE($this);       }, 2000);      } else {       \/\/ \u0421\u043e\u0437\u0434\u0430\u0435\u0442 CORS \u043e\u0431\u044a\u0435\u043a\u0442       mcXHR = xhr = new XMLHttpRequest();        xhr.onreadystatechange = xhr.onload = function () {         if (4 === xhr.readyState) {                      \/\/ \u0415\u0441\u043b\u0438 \u043f\u0440\u0438\u0448\u043b\u043e \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435           if (200 === xhr.status && xhr.responseText.length &gt; 0) {                          \/\/ \u0411\u0435\u0440\u0435\u043c Etag \u0438 Last-Modified \u0438\u0437 Header \u043e\u0442\u0432\u0435\u0442\u0430             $this.etag = xhr.getResponseHeader('Etag');             $this.time = xhr.getResponseHeader('Last-Modified');                          \/\/ \u0412\u044b\u0437\u044b\u0432\u0430\u0435\u043c \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f             $this.action(xhr.responseText);           }                      if (xhr.status &gt; 0) {             \/\/ \u0415\u0441\u043b\u0438 \u043d\u0438\u0447\u0435\u0433\u043e \u043d\u0435 \u043f\u0440\u0438\u0448\u043b\u043e \u043f\u043e\u0432\u0442\u043e\u0440\u044f\u0435\u043c \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u044e             $this.poll($this, xhr);           }         }       };              \/\/ \u041d\u0430\u0447\u0438\u043d\u0430\u0435\u043c long polling       $this.poll($this, xhr);     }   },    poll: function ($this, xhr) {     var timestamp = (new Date()).getTime(),       url = 'http:\/\/stream.example.com\/sub\/' + subID + '?callback=?&v=' + timestamp;       \/\/ timestamp \u043f\u043e\u043c\u043e\u0433\u0430\u0435\u0442 \u0437\u0430\u0449\u0438\u0442\u0438\u0442\u044c \u043e\u0442 \u043a\u0435\u0448\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u0432 \u0431\u0440\u0430\u0443\u0437\u0435\u0440\u0430\u0445      xhr.open('GET', url, true);     xhr.setRequestHeader(&quot;If-None-Match&quot;, $this.etag);     xhr.setRequestHeader(&quot;If-Modified-Since&quot;, $this.time);     xhr.send();   },    \/\/ \u0422\u043e \u0436\u0435 \u0441\u0430\u043c\u043e\u0435 \u0447\u0442\u043e \u0438 poll(), \u0442\u043e\u043b\u044c\u043a\u043e \u0434\u043b\u044f IE   poll_IE: function ($this) {     var xhr = new window.XDomainRequest();     var timestamp = (new Date()).getTime(),       url = 'http:\/\/stream.example.com\/sub\/' + subID + '?callback=?&v=' + timestamp;      xhr.onprogress = function () {};     xhr.onload = function () {       $this.action(xhr.responseText);       $this.poll_IE($this);     };     xhr.onerror = function () {       $this.poll_IE($this);     };     xhr.open('GET', url, true);     xhr.send();   },    action: function (event) {     \/\/ \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u0438 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435, \u0438 \u0442\u0435\u043f\u0435\u0440\u044c \u043c\u043e\u0436\u0435\u043c \u0447\u0442\u043e-\u0442\u043e \u043e\u0431\u043d\u043e\u0432\u0438\u0442\u044c     ...   },    valueToTwoDigits: function (value) {     return ((value &lt; 10) ? '0' : '') + value;   },    \/\/ \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u0434\u0430\u0442\u044b \u0432 \u0432\u0438\u0434\u0435 UTC   dateToUTCString: function () {     var time = this.valueToTwoDigits(date.getUTCHours())         + ':' + this.valueToTwoDigits(date.getUTCMinutes())         + ':' + this.valueToTwoDigits(date.getUTCSeconds());     return this.days[date.getUTCDay()] + ', '            + this.valueToTwoDigits(date.getUTCDate()) + ' '            + this.months[date.getUTCMonth()] + ' '            + date.getUTCFullYear() + ' ' + time + ' GMT';   } } <\/code><\/pre>\n<p>  \u0412\u0430\u0436\u043d\u043e \u0441\u043a\u0430\u0437\u0430\u0442\u044c \u043e \u0434\u0432\u0443\u0445 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0430\u0445 etag \u0438 time.  <\/p>\n<pre><code class=\"javascript\">xhr.setRequestHeader(&quot;If-None-Match&quot;, $this.etag); xhr.setRequestHeader(&quot;If-Modified-Since&quot;, $this.time); <\/code><\/pre>\n<p>  \u0411\u0435\u0437 \u043d\u0438\u0445 long polling \u0440\u0430\u0431\u043e\u0442\u0430\u043b \u0434\u0430\u043b\u0435\u043a\u043e \u043d\u0435 \u0432\u0441\u0435\u0433\u0434\u0430 \u0438 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f \u043f\u0440\u0438\u0445\u043e\u0434\u0438\u043b\u0438 \u0447\u0435\u0440\u0435\u0437 \u0440\u0430\u0437. \u042d\u0442\u0438 \u0434\u0432\u0430 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0430, \u043d\u0443\u0436\u043d\u044b \u043c\u043e\u0434\u0443\u043b\u044e nginx-push-stream-module, \u0434\u043b\u044f \u0438\u0434\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u0438 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0439, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0435\u0449\u0451 \u043d\u0435 \u043f\u043e\u043b\u0443\u0447\u0438\u043b \u043f\u043e\u0434\u043f\u0438\u0441\u0447\u0438\u043a. \u0422\u0430\u043a \u0447\u0442\u043e \u0434\u043b\u044f \u0441\u0442\u0430\u0431\u0438\u043b\u044c\u043d\u043e\u0439 \u0440\u0430\u0431\u043e\u0442\u044b \u044d\u0442\u043e \u043f\u0440\u043e\u0441\u0442\u043e \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e.<\/p>\n<h4>\u0412 \u0437\u0430\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0438<\/h4>\n<p>  \u041c\u0435\u0442\u043e\u0434 \u043e\u043f\u0438\u0441\u0430\u043d\u043d\u044b\u0439 \u0432 \u0434\u0430\u043d\u043d\u043e\u043c \u0442\u043e\u043f\u0438\u043a\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0438 \u0443\u0441\u043f\u0435\u0448\u043d\u043e \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u0432 \u043d\u0430\u0448\u0435\u0439 \u0441\u0438\u0441\u0442\u0435\u043c\u0435 \u043a\u043e\u043c\u043c\u0435\u043d\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f <a href=\"http:\/\/cackle.me\">Cackle<\/a>. \u041a\u0430\u0436\u0434\u044b\u0439 \u0434\u0435\u043d\u044c \u0443 \u043d\u0430\u0441 \u043f\u043e\u0440\u044f\u0434\u043a\u0430 20 000 \u2014 30 000 \u043f\u0430\u0440\u0430\u043b\u043b\u0435\u043b\u044c\u043d\u044b\u0445 \u043f\u043e\u0434\u043f\u0438\u0441\u0447\u0438\u043a\u043e\u0432, \u0438 \u043c\u044b \u043d\u0435 \u0440\u0430\u0437\u0443 \u043d\u0435 \u043d\u0430\u0431\u043b\u044e\u0434\u0430\u043b\u0438 \u043a\u0430\u043a\u0438\u0445 \u043b\u0438\u0431\u043e \u043e\u0448\u0438\u0431\u043e\u043a \u0432 \u0434\u043e\u0441\u0442\u0430\u0432\u043a\u0435 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0439. \u0414\u043b\u044f \u043f\u0440\u043e\u0434\u0430\u043a\u0448\u043d \u0440\u0435\u0448\u0435\u043d\u0438\u044f \u044d\u0442\u043e \u0438\u043c\u0435\u043d\u043d\u043e \u0442\u043e, \u0447\u0442\u043e \u043d\u0430\u0434\u043e.    \t \t\t   \t<\/p>\n<div class=\"clear\"><\/div>\n<\/p><\/div>\n<p> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"http:\/\/habrahabr.ru\/company\/cackle\/blog\/167895\/\"> http:\/\/habrahabr.ru\/company\/cackle\/blog\/167895\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div class=\"content html_format\">   \t\u041a\u0430\u043a \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c long polling \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e Nginx \u0438 Javascript \u0432 \u0441\u0435\u0442\u0438 \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u043c\u043d\u043e\u0433\u043e \u043c\u0430\u0442\u0435\u0440\u0438\u0430\u043b\u0430. \u041d\u043e \u043f\u043e\u043b\u043d\u043e\u0433\u043e \u0440\u0443\u043a\u043e\u0432\u043e\u0434\u0441\u0442\u0432\u0430 \u044f \u0435\u0449\u0451 \u043d\u0435 \u0432\u0441\u0442\u0440\u0435\u0447\u0430\u043b. \u0422\u043e \u0432\u043e\u0437\u043d\u0438\u043a\u0430\u044e\u0442 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u044b \u0441 \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0446\u0438\u0435\u0439 \u043c\u043e\u0434\u0443\u043b\u044f \u043f\u043e\u0434 Nginx, \u0442\u043e \u0432 \u0431\u0440\u0430\u0443\u0437\u0435\u0440\u0435 \u0432\u0435\u0440\u0442\u0438\u0442\u0441\u044f \u0438\u043a\u043e\u043d\u043a\u0430 \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0438 \u043f\u0440\u0438 long poll \u0437\u0430\u043f\u0440\u043e\u0441\u0430\u0445. \u041f\u043e\u0434 \u043a\u0430\u0442\u043e\u043c, \u043f\u043e\u043b\u043d\u044b\u0439 \u043c\u0430\u0442\u0435\u0440\u0438\u0430\u043b \u043a\u0430\u043a \u0436\u0435 \u0432\u0441\u0435 \u0442\u0430\u043a\u0438 \u044d\u0442\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e.  <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-167895","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/167895","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=167895"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/167895\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=167895"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=167895"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=167895"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}