I'm trying to setup a feature on my site that allows users to know
wich users are connected (using a picto green light/red light).
Is there a "good way" to do this ? Is there a symfony feature that can
help me ?
Actually, I've succeeded by coding a function ping() placed in every
actions.class preExecute().
But that seems pretty heavy to update a field "last_ping" in my users
table at every requests...
<benjamin.vi...@hamburware.com> wrote: > Is there a "good way" to do this ? Is there a symfony feature that can > help me ?
Something less accurate but performance-proof is to update a last_connected_at column in your user model at authentication time, then you can test for each user if his connection time is less than a configureable amount of time (eg. 5 minutes)
The problem with this solution is that if the user is connected since
more than 5 minutes he will be considered offline.
And if I set something like 20 minutes it won't proof that the user is
online...
Is it possible to put a piece of code (maybe javascript ?) somewhere
to refresh the last_ping DB field every X minutes ?
thank you !
On Jul 23, 9:52 am, "Nicolas Perriault" <nperria...@gmail.com> wrote:
> <benjamin.vi...@hamburware.com> wrote:
> > Is there a "good way" to do this ? Is there a symfony feature that can
> > help me ?
> Something less accurate but performance-proof is to update a
> last_connected_at column in your user model at authentication time,
> then you can test for each user if his connection time is less than a
> configureable amount of time (eg. 5 minutes)
> Is it possible to put a piece of code (maybe javascript ?) somewhere
> to refresh the last_ping DB field every X minutes ?
Yes, you could certainly do that and just have an ajax POST request
update the value every 5 minutes or so. You'd have to use a javascript
timer to fire off the request after some timeout has been achieved and
recalculate that timeout value after each request.
Another good approach you could take is to use memcache to store this
information, as opposed to putting it in the database. Memcache (if
you're not familiar with it) essentially runs as a daemon on the
server, similar to a database server, except that it allows you to
persist data in the server's memory, so read and write operations are
VERY fast. This could be a good thing to utilize for tracking whether
or not a user is online as opposed to writing to the database for each
request... plus memcache is good to use for caching data and other
stuff.
jonathan
On Jul 23, 6:04 am, Benjamin <benjamin.vi...@hamburware.com> wrote:
> The problem with this solution is that if the user is connected since
> more than 5 minutes he will be considered offline.
> And if I set something like 20 minutes it won't proof that the user is
> online...
> Is it possible to put a piece of code (maybe javascript ?) somewhere
> to refresh the last_ping DB field every X minutes ?
> thank you !
> On Jul 23, 9:52 am, "Nicolas Perriault" <nperria...@gmail.com> wrote:
> > On Tue, Jul 22, 2008 at 11:27 AM, Benjamin
> > <benjamin.vi...@hamburware.com> wrote:
> > > Is there a "good way" to do this ? Is there a symfony feature that can
> > > help me ?
> > Something less accurate but performance-proof is to update a
> > last_connected_at column in your user model at authentication time,
> > then you can test for each user if his connection time is less than a
> > configureable amount of time (eg. 5 minutes)
On Wed, Jul 23, 2008 at 3:04 PM, Benjamin <benjamin.vi...@hamburware.com> wrote: > The problem with this solution is that if the user is connected since > more than 5 minutes he will be considered offline. > And if I set something like 20 minutes it won't proof that the user is > online...
You can update a "last_active_at" field on every action the user does, or take advantage of a database session storage, adding this "last_active_at" timestamp in the session table at writing time, then you could poll it to see real users activity... But it can be very heavy, I guess.
Maybe using memcache as suggested could solve your problem more efficiently...
I think I'm going to explore memcache, but it's the first time I hear
about it, so it might be a little difficult...
By the way, for the Ajax post solution, I really don't know where I
can put this piece of code. I thought about the layout but it is
refreshed at every request so the timer too...
On Jul 23, 9:54 pm, "Nicolas Perriault" <nperria...@gmail.com> wrote:
> On Wed, Jul 23, 2008 at 3:04 PM, Benjamin <benjamin.vi...@hamburware.com> wrote:
> > The problem with this solution is that if the user is connected since
> > more than 5 minutes he will be considered offline.
> > And if I set something like 20 minutes it won't proof that the user is
> > online...
> You can update a "last_active_at" field on every action the user does,
> or take advantage of a database session storage, adding this
> "last_active_at" timestamp in the session table at writing time, then
> you could poll it to see real users activity... But it can be very
> heavy, I guess.
> Maybe using memcache as suggested could solve your problem more efficiently...
I think the best solution is still to observe a last-update
(updated_at) field of a database session and to query all sessions in
the last 5 minutes, for example. This is still the best way IMO to
recognize a "real" user action, i mean, he is still there.
Imagine i leave my computer for lunch or something. A javascript
"heartbeat" will fail your question "Is this user still there?".
Michael
On Jul 24, 10:29 am, Benjamin <benjamin.vi...@hamburware.com> wrote:
> I think I'm going to explore memcache, but it's the first time I hear
> about it, so it might be a little difficult...
> By the way, for the Ajax post solution, I really don't know where I
> can put this piece of code. I thought about the layout but it is
> refreshed at every request so the timer too...
> On Jul 23, 9:54 pm, "Nicolas Perriault" <nperria...@gmail.com> wrote:
> > On Wed, Jul 23, 2008 at 3:04 PM, Benjamin <benjamin.vi...@hamburware.com> wrote:
> > > The problem with this solution is that if the user is connected since
> > > more than 5 minutes he will be considered offline.
> > > And if I set something like 20 minutes it won't proof that the user is
> > > online...
> > You can update a "last_active_at" field on every action the user does,
> > or take advantage of a database session storage, adding this
> > "last_active_at" timestamp in the session table at writing time, then
> > you could poll it to see real users activity... But it can be very
> > heavy, I guess.
> > Maybe using memcache as suggested could solve your problem more efficiently...
<michael.pie...@googlemail.com> wrote:
> I think the best solution is still to observe a last-update
> (updated_at) field of a database session and to query all sessions in
> the last 5 minutes, for example. This is still the best way IMO to
> recognize a "real" user action, i mean, he is still there.
> Imagine i leave my computer for lunch or something. A javascript
> "heartbeat" will fail your question "Is this user still there?".
> Michael
> On Jul 24, 10:29 am, Benjamin <benjamin.vi...@hamburware.com> wrote:
> > Thank you for your responses.
> > I think I'm going to explore memcache, but it's the first time I hear
> > about it, so it might be a little difficult...
> > By the way, for the Ajax post solution, I really don't know where I
> > can put this piece of code. I thought about the layout but it is
> > refreshed at every request so the timer too...
> > > On Wed, Jul 23, 2008 at 3:04 PM, Benjamin <benjamin.vi...@hamburware.com> wrote:
> > > > The problem with this solution is that if the user is connected since
> > > > more than 5 minutes he will be considered offline.
> > > > And if I set something like 20 minutes it won't proof that the user is
> > > > online...
> > > You can update a "last_active_at" field on every action the user does,
> > > or take advantage of a database session storage, adding this
> > > "last_active_at" timestamp in the session table at writing time, then
> > > you could poll it to see real users activity... But it can be very
> > > heavy, I guess.
> > > Maybe using memcache as suggested could solve your problem more efficiently...
On Thu, Jul 24, 2008 at 2:58 PM, Benjamin <benjamin.vi...@hamburware.com> wrote: > Michael's solution sounds great ! But I take the risk to be treated > as a noob : I don't know what is a database session...
> I'm going to read some documentations, if you have any tips or a good > link don't hesitate ;-)
> On Thu, Jul 24, 2008 at 2:58 PM, Benjamin <benjamin.vi...@hamburware.com> wrote:
> > Michael's solution sounds great ! But I take the risk to be treated
> > as a noob : I don't know what is a database session...
> > I'm going to read some documentations, if you have any tips or a good
> > link don't hesitate ;-)