PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Autres forums > Forum Programmation & Conception > comp.lang.php > Sessions
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
Sessions

Réponse
 
LinkBack Outils de la discussion
Vieux 21/01/2008, 13h33   #1
Pankaj
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Sessions

Hi,

My site works on sessions. Currently when a user logs in, I store all
information in a database table. Whenever the user does something, I
check the database to see if the session is active. If so, I update
the date and time and then update the other tables. If the seesion is
not active, I ask him to enter his password again. A cron job runs
every 30 mins to clean up the inactive sessions.

The problem with this approach is that it puts a huge load on the
database server as for every activity I have to check one table and
based on its value, I perform other operations. What could be a more
effective way of handling this ? I cannot rely on the session file
created when I start a session because if a user closes the browser
window without logging out, I should be able to mark that session as
closed.

Thanks
Pankaj
  Réponse avec citation
Vieux 21/01/2008, 15h38   #2
god.lightgod@gmail.com
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Sessions

On jan. 21, 14:33, Pankaj <panah...@gmail.com> wrote:
> Hi,
>
> My site works on sessions. Currently when a user logs in, I store all
> information in a database table. Whenever the user does something, I
> check the database to see if the session is active. If so, I update
> the date and time and then update the other tables. If the seesion is
> not active, I ask him to enter his password again. A cron job runs
> every 30 mins to clean up the inactive sessions.
>
> The problem with this approach is that it puts a huge load on the
> database server as for every activity I have to check one table and
> based on its value, I perform other operations. What could be a more
> effective way of handling this ? I cannot rely on the session file
> created when I start a session because if a user closes the browser
> window without logging out, I should be able to mark that session as
> closed.
>
> Thanks
> Pankaj


CREATE TABLE `session` (
id not null auto_increment primary_key,
...
phpsessid ...,
...
login datetime
);

ok... Sry... This is a very stupid sample... I don't know what you
want logging...
And now... If the user visit the site you check `session`.`login`
field.... login-current time... if negative Get her/his password...
And...
session_start();
session_cache_expire(time() + 60 * MINUTE_LIMIT);

I think... nuff sed...
  Réponse avec citation
Vieux 21/01/2008, 15h43   #3
god.lightgod@gmail.com
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Sessions

On jan. 21, 14:33, Pankaj <panah...@gmail.com> wrote:
> Hi,
>
> My site works on sessions. Currently when a user logs in, I store all
> information in a database table. Whenever the user does something, I
> check the database to see if the session is active. If so, I update
> the date and time and then update the other tables. If the seesion is
> not active, I ask him to enter his password again. A cron job runs
> every 30 mins to clean up the inactive sessions.
>
> The problem with this approach is that it puts a huge load on the
> database server as for every activity I have to check one table and
> based on its value, I perform other operations. What could be a more
> effective way of handling this ? I cannot rely on the session file
> created when I start a session because if a user closes the browser
> window without logging out, I should be able to mark that session as
> closed.
>
> Thanks
> Pankaj


oh... and... into the table... UID... One User One Sessid... if the
session is... time out...at the next UserLogin... You update her/his
rowin the session table ^_^ is not in this manner duplicating and it
is not necessary to deal with the unnecessary entries very much.
  Réponse avec citation
Vieux 22/01/2008, 06h33   #4
Pankaj
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Sessions

>
> oh... and... into the table... UID... One User One Sessid... if the
> session is... time out...at the next UserLogin... You update her/his
> rowin the session table ^_^ is not in this manner duplicating and it
> is not necessary to deal with the unnecessary entries very much.


I still have to update the table everytime I have to perform an
operation any other table. My site typically has 300 users at any
given instance and I need to check and update this table around 300
times in 10 secs before I can work on any other table. This causes an
unnecessary delay and load.
  Réponse avec citation
Vieux 22/01/2008, 09h32   #5
C. (http://symcbean.blogspot.com/)
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Sessions

On 22 Jan, 06:33, Pankaj <panah...@gmail.com> wrote:
> > oh... and... into the table... UID... One User One Sessid... if the
> > session is... time out...at the next UserLogin... You update her/his
> > rowin the session table ^_^ is not in this manner duplicating and it
> > is not necessary to deal with the unnecessary entries very much.

>
> I still have to update the table everytime I have to perform an
> operation any other table. My site typically has 300 users at any
> given instance and I need to check and update this table around 300
> times in 10 secs before I can work on any other table. This causes an
> unnecessary delay and load.


That's not a huge amount of traffic - if your DB schema is set up
properly there should be little difference compared with using files
for sessions.

> Whenever the user does something, I
> check the database to see if the session is active. If so, I update
> the date and time and then update the other tables.


If you're using PHP sessions and a database bound session handler....

The session should always be stored at the end of each request - if
you're writing the session data manually for each request then you're
doubling the workload. Also, the session will be loaded automatically
as soon as you call session_start() from your code - if (!
count($_SESSION)) then the user doesn't have a current session - no
need to refer to the database again.

C.

  Réponse avec citation
Vieux 22/01/2008, 13h20   #6
Jerry Stuckle
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Sessions

Pankaj wrote:
> Hi,
>
> My site works on sessions. Currently when a user logs in, I store all
> information in a database table. Whenever the user does something, I
> check the database to see if the session is active. If so, I update
> the date and time and then update the other tables. If the seesion is
> not active, I ask him to enter his password again. A cron job runs
> every 30 mins to clean up the inactive sessions.
>
> The problem with this approach is that it puts a huge load on the
> database server as for every activity I have to check one table and
> based on its value, I perform other operations. What could be a more
> effective way of handling this ? I cannot rely on the session file
> created when I start a session because if a user closes the browser
> window without logging out, I should be able to mark that session as
> closed.
>
> Thanks
> Pankaj
>


I still don't understand why you're going through all this trouble. Why
aren't you just storing the data in the session itself? That's what
it's there for.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================

  Réponse avec citation
Vieux 23/01/2008, 10h08   #7
Toby A Inkster
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Sessions

Jerry Stuckle wrote:
> Pankaj wrote:
>
>> I cannot rely on the session file created when I start a session
>> because if a user closes the browser window without logging out, I
>> should be able to mark that session as closed.

>
> I still don't understand why you're going through all this trouble. Why
> aren't you just storing the data in the session itself? That's what
> it's there for.


Indeed. PHP tidies up session files after a specified period of inactivity
in much the same way as he's described his own code doing.

--
Toby A Inkster BSc (Hons) ARCS
[Geek of HTML/SQL/Perl/PHP/Python/Apache/Linux]
[OS: Linux 2.6.17.14-mm-desktop-9mdvsmp, up 23 days, 21:19.]

CSS to HTML Compiler
http://tobyinkster.co.uk/blog/2008/01/22/css-compile/
  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 18h24.


Édité par : vBulletin® version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières ©2000-2008
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,17574 seconds with 15 queries