Yii Framework Forum: Event Driven Front End On Yii - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Event Driven Front End On Yii Rate Topic: -----

#1 User is offline   Tibor Katelbach 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 81
  • Joined: 11-April 11
  • Location:Reunion Island

Posted 16 November 2012 - 08:16 AM

Hi
I'm wondering what would be the best way to do user event driven front ends in Yii
what I mean is : let's say many people are on one same page (=url)
if a status of something is changed by a user
how to make it refresh to everyone

I know the ajax pinging technique but it's so slow, and generates constent pinging requests
I also looked into websockets which is far from being a standard and unavailable on all browsers for the moment
which brings me to the Forum
can it be done smoothly using Yii ?
or should I look into other frameworks like nodeJS

I'd prefer to stick with Yii since my whole application is on Yii

Thanks for the insight
Tibor
0

#2 User is offline   KonApaz 

  • Elite Member
  • PipPipPipPipPip
  • Yii
  • Group: Members
  • Posts: 1,323
  • Joined: 21-February 11
  • Location:Greece

Posted 16 November 2012 - 09:01 AM

Hi Tibor

You could create a function called onBeginRequest and set a variable according to sql data
this sql data will be set when user status changed
Yii is the best php framework in the world!
find our demo Yii extension on www.webkit.gr
Is it post useful? please v++ ;)
0

#3 User is offline   Ben 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 270
  • Joined: 15-March 09

Posted 16 November 2012 - 09:30 AM

If there way an easy solution for this, I guess we'd see much more really nice websites. ;)

From my point of view, what you need to do is to define an abstract notification mechanism, that allows your server to send messages to the clients. I'd probably go with an observer pattern, defining the subject as an interface in your yii app. The observer would be a javascript class, for simplicity with the common "notify" method that is (conceptually) called by the subject when something happened. This way, you could get events from the server to your connected clients (all the browsers that visit the page).

Every connected client might implement a similar pattern to re-distribute incomming messages to interested components of client side logic, but this has no longer to do with passing messages from server to client...

My point is: as soon as you have established the concept of passing messages from server to client, and you have a defined interface, everything else becomes an implementation detail.

If you have to to stick with http, the server can't push to the clients. So your subject implementation might store the events in db (together with connected client IDs). The javascript observer implementation would poll (maybe implement long polling/ comet) and receive the messages stored in DB (message/clientID tuple can be deleted after they have been requested).

If you have clients that know how to work with websockets, you can provide a second implementation of your subject, that doesn't need to store messages for later retrieval, but simply pushes them to the bleeding edge client.

The benefit is, that the matter of how the message finds its way to the client is transparent to your yii application. It only works with the subject interface you defined in the first step.

So in a nutshell: Yii probably won't do much to help you accomplish the message passing piece of work. But it can be implemented and if done right, it can be re-used as an extension.

Oh, and I'd love to hear some more opinions on that topic. :)
Don't like ads in my sig...
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users