
http { … server { … location /publish { push_stream_publisher admin; #      push_stream_channels_path $arg_id; # id     push_stream_store_messages on; #      allow 127.0.0.1; #         } location ~ /subscribe/(.*) { push_stream_subscriber long-polling ; #     # (  ) push_stream_channels_path $1; # id    push_stream_longpolling_connection_ttl 300s; #  ,     #   ( )  #  push_stream_last_received_message_time $arg_time; #     push_stream_last_received_message_tag $arg_tag; # ,    # } } push_stream_shared_memory_size 32M; }  $channel_id = subscriber1; //id     $message='!'; //  //  $ch = curl_init('http://127.0.0.1/publish?id='.$channel_id); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($message)); curl_exec($ch); curl_close($ch);  var channelId = subscriber1; //id  var last_etag=0; //   'Etag' var last_time=null; //   'Last-Modified' function new_message() { $.ajax({ url: '/subscribe/' + channelId, type: "GET", dataType: 'json', beforeSend: function(xhr){xhr.setRequestHeader('Etag', last_etag);xhr.setRequestHeader('Last-Modified', last_time);}, success: function(data, status, xhr) { last_etag =xhr.getResponseHeader('Etag'); //    last_etag //   'Etag'  last_time =xhr.getResponseHeader('Last-Modified'); //     last_time //   'Last-Modified'  // -     setTimeout(new_message, 500); //      } }) } new_message(); Source: https://habr.com/ru/post/252349/
All Articles