Long Polling/HTTP Streaming General Questions

Asked
Active3 hr before
Viewed126 times

4 Answers

streaming
90%

Stack Overflow Public questions & answers ,Stack Overflow en español,After someone enters the chat room a new Ajax long poll request is being made., Podcast 392: Do polyglots have an edge when it comes to mastering programming...

To see the JS code simply view source. The PHP code is:

< ? php
$updates = $_GET['updates'];
if (!$updates) {
   $updates = 100;
}

header('Content-type: text/plain');
echo str_pad('PADDING', 2048, '|PADDING'); // initial buffer required

$sleep_time = 1;
$count = 0;
$update_suffix = 'Just keep streaming, streaming, streaming. Just keep streaming.';
while ($count < 100) {
   $message = $count.
   ' >> '.$update_suffix;
   echo($message);
   flush();
   $count = $count + 1;
   sleep($sleep_time);
} ?
>
88%

All of these concerns, and more need to be considered when implementing robust support for long polling in any realtime messaging system.,Try our APIs and see why developers from startups to industrial giants choose to build on Ably because they simplify engineering, minimize DevOps overhead, and increase development velocity.,Easily power any realtime experience in your application. No complex infrastructure to manage or provision. Just a simple API that handles everything realtime, and lets you focus on your code.,As long polling is really just an improvisation applied to an underlying request-response mechanism, it comes with an additional degree of complexity in its implementation. There are various concerns you’ll need to account for when considering the design of your system’s architecture.

import "github.com/jcuga/golongpoll"

// This launches a goroutine and creates channels for all the plumbing
manager, err: = golongpoll.StartLongpoll(golongpoll.Options {}) // default options

// Pass the manager around or create closures and publish:
manager.Publish("subscription-category", "Some data.  Can be string or any obj convertible to JSON")
manager.Publish("different-category", "More data")

// Expose events to browsers
// See subsection on how to interact with the subscription handler
http.HandleFunc("/events", manager.SubscriptionHandler)
http.ListenAndServe("127.0.0.1:8081", nil)
load more v
72%

The two most common server push mechanisms are "HTTP long polling" and "HTTP streaming": ,An HTTP/1.0 server can use only EOF as a streaming mechanism. By contrast, both EOF and "chunked transfer" are available to an HTTP/1.1 server. ,The HTTP long polling mechanism introduces the following issues. ,The HTTP streaming mechanism is based on the capability of the server to send several pieces of information on the same response, without terminating the request or the connection. This result can be achieved by both HTTP/1.1 and HTTP/1.0 servers.

        HTTP / 1.1 200 OK
        Content - Type: text / plain
        Transfer - Encoding: chunked

        25
        This is the data in the first chunk

        1 C
        and this is the second one

        0
65%

I am trying to create a theoretical web chat application with php and jquery , I read about long polls and HTTP streams, and I managed to apply most of the principles presented in the articles. However, there are two main things that I still cannot omit.,I hope that my illustration is easy to understand, but the message queue is a very wide topic, so refer to the resources mentioned above for further reading.,Therefore, instead of continuously querying your database, you can simply subscribe to the MQ event and just hang until someone else posts the message you are subscribed to and MQ wakes you up and sends a message. A chat application is a very useful occasion to understand this functionality.,It doesn't seem like you can achieve the same functionality using jQuery.ajax . The success callback does not fire every time the onreadystatechange event is onreadystatechange . This is surprising since the documentation states:

To see the JS code, just browse the source. PHP code:

 < ? php $updates = $_GET['updates'];
 if (!$updates) {
    $updates = 100;
 }
 header('Content-type: text/plain');
 echo str_pad('PADDING', 2048, '|PADDING'); // initial buffer required $sleep_time = 1; $count = 0; $update_suffix = 'Just keep streaming, streaming, streaming. Just keep streaming.'; while($count < 100) { $message = $count . ' >> ' . $update_suffix; echo($message); flush(); $count = $count + 1; sleep($sleep_time); } ?> 

Other "streaming-undefined" queries related to "Long Polling/HTTP Streaming General Questions"