Note that there are some explanatory texts on larger screens.

plurals
  1. POHow can I provide real-time notifications without tying up resources?
    primarykey
    data
    text
    <p>I'm using AJAX to implement <a href="http://jfarcand.wordpress.com/2007/05/15/new-adventures-in-comet-polling-long-polling-or-http-streaming-with-ajax-which-one-to-choose/" rel="nofollow">long polling</a> on a page which I want to update whenever new rows are inserted into the database. The way this is done is with jQuery's <code>.ajax()</code> calling, for example, <code>poll.php?ky=41</code>, which queries the database a number of times for rows with an ID of <code>&gt; 41</code> (with a small wait in between) until a specified timeout. It will fulfil the request immediately if there is a result, or after the given timeout.</p> <p>In effect, this keeps a hidden connection always open to the server, waiting for it to respond, in order to get notifications.</p> <p>This works, but I'm using DreamHost and after 8 <code>php53.cgi</code> worker processes are spawned, no requests to my site are fulfilled (i.e. forever loading) until one times out. This affects every other page on my website. The HTTP Server is Apache 2.2.22-14.</p> <p>To alleviate the problem, I have reduced the delays and the timeouts so it is closer to regular polling, and added longer delays when there have been no updates for a while. This means notifications may come a few seconds late, but so far my server has been running fine.</p> <p>What I'm worried about is how well (or rather, how poorly) this will scale.</p> <p>My question is: given that I'm on a shared host (DreamHost), and this page must be compatible with as many browsers as possible (except mobile), is there a more efficient way to get instant "push" notifications from the server?</p> <p>Or, what other options do I have? Should I switch back to regular polling?</p> <h2>TL; DR</h2> <p>Polling is fast, but long-polling (waiting before fulfilling the AJAX request) ties up resources. The difference is that long-polling will get the result as soon as it arrives, whereas polling will only pick it up the next time an AJAX request is sent after the new information comes in. Ideally, I would like the advantage of long-polling without tying up threads &amp; causing other users to wait before pages are served.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload