1

I'm currently developing a website that requires a push notification style system like Facebook notifications. I would like the user to be notified when an event occurs such as "X added you as a friend"...

I've been looking into my options however they seem to be extremely limited as the website will be hosted on a shared hosting platform therefore I have limited access etc.

1) Looking at long polling comet style - as I can't run Python on the server, my only option here is PHP for the server script however due to thread consumption this probably isn't a very scalable option.

2) WebSockets - these look great but with browser support limited it doesn't seem plausible just yet..

So - has anyone accomplished this on a shared hosting platform? I'd rather not have to use a service like Pusher.

Many thanks!! :)

PS - I'm using Yii framework - any solutions with that in mind would be even better

cud_programmer
  • 1,244
  • 1
  • 20
  • 37

3 Answers3

1

use Ratchet , it is a WebSocket for PHP.

Ratchet is a loosely coupled PHP library providing developers with tools to create real time, bi-directional applications between clients and servers over WebSockets. This is not your Grandfather's Internet.

here is a helloworld example.

Saleh Mosleh
  • 504
  • 5
  • 12
0

Use html5 SSE (Server sent dom events) for chrome, firefox, opera and ie10

for older versions of IE use iframe loading as a fallback.

all those techniques should work well with any kind of shared hosting since they do not require any kind of server side setup.

Silver Moon
  • 1,086
  • 14
  • 19
-1

https://stackoverflow.com/a/1086448/1063333 :

A common method of doing such notifications is to poll a script on the server (using ajax) on a given interval (perhaps every few seconds), to check if something has happened

Community
  • 1
  • 1
Zul
  • 3,627
  • 3
  • 21
  • 35
  • thanks, but I've read that already. It doesn't really help much as it requires timeout to be huge and this isn't allowed on shared hosting :( – cud_programmer Jun 30 '12 at 18:00
  • That shouldn't be an issue, if you poll you don't need long time-outs. – Luc Franken Jun 30 '12 at 18:09
  • 1
    @LucFranken surely by polling though it's extremely resource consuming? I guess though, any implementation on shared hosting is heavily resource consuming.. – cud_programmer Jun 30 '12 at 18:11
  • I don't expect much problems if you make it smart and cached. So don't fire complex queries for every user every second. Anyhow when you are on shared hosting I expect you don't host lots and lots of users at all at the same time. – Luc Franken Jun 30 '12 at 18:12
  • You can offload the distribution of new content/live updates to a 3rd party solution. See http://www.leggetter.co.uk/real-time-web-technologies-guide#hosted-client – leggetter Jul 02 '12 at 12:05