Search code examples
javascriptcakephppush-notificationlong-polling

CakePHP SSE or Hanging Get


During piloting of new web app there was a request for feedback from the server, whilst it is performing certian tasks, like new collaborators on a document and log outs, etc.

So I implemented SSE (Sever-Sent Events) and it works fine and we are able to get the right feedback and nice in app messages 'Growl Style'.

My Question is this: Should I really be using SSE For push or just used good old Hanging Get.

From ITs point of view SSE seems to be fine but during certain tasks the app sets the rerty field retry: 500 so this increases the number of called to the server.

When I used Facebook like push notification (Hanging Get) I only get feedback when I am supposed to without checking.

-

Extraneous details

*We do not want to use web sockets at this time. I have implemented this but the app won't require this often.

Its not hard for me to use either SSE or Polling anytime, since I have an interfaces that I implement to an abstract class named PushService(); so at any time I can swap between SSEService and PollService *


Solution

  • Well, the facts are:

    • SSE and Long Polling ("Hanging Get") accomplish the same thing -- pushing data from the server to the client when the server is ready.

    • Long Polling requires a hack to implement. SSE does not.

    • Long Polling works in all modern web browsers. SSE works in newer versions of most modern browsers, but does not work in any version of Internet Explorer (up to IE9 at the time of this writing).

    Given these facts, it seems like the decision between these two is clear. If you need to support Internet Explorer or older versions of other browsers (e.g., most public-facing apps), use Long Polling. If you know you never will need to support those browsers (e.g., certain internal apps like company admin interfaces), use SSE.

    Since your case is a pilot for a new web app, it seems likely you'll want to support as many browsers as possible, so go with Long Polling. You also mentioned in your question that Long Polling reduces the load on your server anyway, so that's an added bonus here.