PHWinfo banniere

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

Réponse
 
LinkBack Outils de la discussion
Vieux 07/05/2008, 17h27   #1
Scott Campbell
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut $_SESSION v.

Dear PHP List,

PHP 5, Apache2, MySQL 5, running on Ubuntu, viewing & deving with
FireFox and Konqueror (Linux).

I am building a site with multiple tools and want to pass variables
throughout them all. Before, I was passing variables using <hidden> HTML
Form tags, but the site has grown too large for this tactic, so I went to
using $_SESSION. However, when I started using $_SESSION, my site loads 3-5
times slower then before. A page that queried MySQL and built itself in 3-5
seconds was now taking 15-20. While more has changed then just $_SESSION,
it is really the only significant difference.

Is $_SESSION slowing down my site? Is there a faster alternative to
global variables then using $_SESSION? Are using regular faster?

Any is appreciated.

Thanks,
Scott

--
Scott Campbell
"If you do what you've always done, you'll get what you've always gotten."

"Courage is resistance to fear .. not absence of fear."

  Réponse avec citation
Vieux 07/05/2008, 17h34   #2
Robert Cummings
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: [PHP] $_SESSION v.


On Wed, 2008-05-07 at 12:27 -0400, Scott Campbell wrote:
> Dear PHP List,
>
> PHP 5, Apache2, MySQL 5, running on Ubuntu, viewing & deving with
> FireFox and Konqueror (Linux).
>
> I am building a site with multiple tools and want to pass variables
> throughout them all. Before, I was passing variables using <hidden> HTML
> Form tags, but the site has grown too large for this tactic, so I went to
> using $_SESSION. However, when I started using $_SESSION, my site loads 3-5
> times slower then before. A page that queried MySQL and built itself in 3-5
> seconds was now taking 15-20. While more has changed then just $_SESSION,
> it is really the only significant difference.
>
> Is $_SESSION slowing down my site? Is there a faster alternative to
> global variables then using $_SESSION? Are using regular faster?
>
> Any is appreciated.


How are your sessions implemented? Are you using the stock PHP session
functionality or did you cook your own solution? I can't see the stock
PHP solution adding anything more than a split second to your page time.
The exception being when it performs cleanup. Cleanup should be
relegated to a cron job. Have you added anything new to the database?
new query perhaps on a large table that doesn't make use of indexes?
Small changes can have a bigger impact than large changes depending on
what exactly changed.

Cheers,
Rob.
--
http://www.interjinn.com
Application and Templating Framework for PHP

  Réponse avec citation
Vieux 07/05/2008, 21h03   #3
tedd
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: [PHP] $_SESSION v.

At 12:34 PM -0400 5/7/08, Robert Cummings wrote:
>
>The exception being when it performs cleanup. Cleanup should be
>relegated to a cron job.


Rob:

What clean-up?

Cheers,

tedd
--
-------
http://sperling.com http://ancientstones.com http://earthstones.com
  Réponse avec citation
Vieux 07/05/2008, 21h22   #4
Robert Cummings
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: [PHP] $_SESSION v.


On Wed, 2008-05-07 at 16:03 -0400, tedd wrote:
> At 12:34 PM -0400 5/7/08, Robert Cummings wrote:
> >
> >The exception being when it performs cleanup. Cleanup should be
> >relegated to a cron job.

>
> Rob:
>
> What clean-up?


All the inactive session files... inactive and garbage collection time
is denoted by the following php.ini settings:

session.gc_probability = 1 ; percentual probability that the
; 'garbage collection' process is
; started
; on every session initialization
session.gc_maxlifetime = 1440 ; after this number of seconds,
; stored data will be seen as
; 'garbage' and cleaned up by the
; gc process

Cheers,
Rob.
--
http://www.interjinn.com
Application and Templating Framework for PHP

  Réponse avec citation
Vieux 07/05/2008, 21h29   #5
Nathan Nobbe
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: [PHP] $_SESSION v.

On Wed, May 7, 2008 at 2:22 PM, Robert Cummings <robert@interjinn.com>
wrote:

>
> On Wed, 2008-05-07 at 16:03 -0400, tedd wrote:
> > At 12:34 PM -0400 5/7/08, Robert Cummings wrote:
> > >
> > >The exception being when it performs cleanup. Cleanup should be
> > >relegated to a cron job.

> >
> > Rob:
> >
> > What clean-up?

>
> All the inactive session files... inactive and garbage collection time
> is denoted by the following php.ini settings:
>
> session.gc_probability = 1 ; percentual probability that the
> ; 'garbage collection' process is
> ; started
> ; on every session initialization
> session.gc_maxlifetime = 1440 ; after this number of seconds,
> ; stored data will be seen as
> ; 'garbage' and cleaned up by the
> ; gc process



so where is the setting, using the stock session handler, to relegate the gc
process to a cron job ?

-nathan

  Réponse avec citation
Vieux 07/05/2008, 21h30   #6
tedd
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: [PHP] $_SESSION v.

At 4:22 PM -0400 5/7/08, Robert Cummings wrote:
>On Wed, 2008-05-07 at 16:03 -0400, tedd wrote:
>> At 12:34 PM -0400 5/7/08, Robert Cummings wrote:
>> >
>> >The exception being when it performs cleanup. Cleanup should be
>> >relegated to a cron job.

>>
>> Rob:
>>
>> What clean-up?

>
>All the inactive session files... inactive and garbage collection time
>is denoted by the following php.ini settings:
>
>session.gc_probability = 1 ; percentual probability that the
> ; 'garbage collection' process is
> ; started
> ; on every session initialization
>session.gc_maxlifetime = 1440 ; after this number of seconds,
> ; stored data will be seen as
> ; 'garbage' and cleaned up by the
> ; gc process
>
>Cheers,
>Rob.


Oh, Okay. That's an automatic practice taken from the php.ini
settings. I was thinking that maybe one was supposed to do something
after using sessions.

Thanks,

tedd

--
-------
http://sperling.com http://ancientstones.com http://earthstones.com
  Réponse avec citation
Vieux 07/05/2008, 21h35   #7
Robert Cummings
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: [PHP] $_SESSION v.


On Wed, 2008-05-07 at 14:29 -0600, Nathan Nobbe wrote:
> On Wed, May 7, 2008 at 2:22 PM, Robert Cummings <robert@interjinn.com>
> wrote:
>
> On Wed, 2008-05-07 at 16:03 -0400, tedd wrote:
> > At 12:34 PM -0400 5/7/08, Robert Cummings wrote:
> > >
> > >The exception being when it performs cleanup. Cleanup

> should be
> > >relegated to a cron job.

> >
> > Rob:
> >
> > What clean-up?

>
>
> All the inactive session files... inactive and garbage
> collection time
> is denoted by the following php.ini settings:
>
> session.gc_probability = 1 ; percentual probability
> that the
> ; 'garbage collection'
> process is
> ; started
> ; on every session
> initialization
> session.gc_maxlifetime = 1440 ; after this number of
> seconds,
> ; stored data will be seen as
> ; 'garbage' and cleaned up by
> the
> ; gc process
>
> so where is the setting, using the stock session handler, to relegate
> the gc process to a cron job ?


session.gc_probability = 0

Then do it yourself in a script called by cron.

Cheers,
Rob.

--
http://www.interjinn.com
Application and Templating Framework for PHP

  Réponse avec citation
Vieux 07/05/2008, 21h55   #8
Nathan Nobbe
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: [PHP] $_SESSION v.

On Wed, May 7, 2008 at 2:35 PM, Robert Cummings <robert@interjinn.com>
wrote:

>
> On Wed, 2008-05-07 at 14:29 -0600, Nathan Nobbe wrote:
> > On Wed, May 7, 2008 at 2:22 PM, Robert Cummings <robert@interjinn.com>
> > wrote:
> >
> > On Wed, 2008-05-07 at 16:03 -0400, tedd wrote:
> > > At 12:34 PM -0400 5/7/08, Robert Cummings wrote:
> > > >
> > > >The exception being when it performs cleanup. Cleanup

> > should be
> > > >relegated to a cron job.
> > >
> > > Rob:
> > >
> > > What clean-up?

> >
> >
> > All the inactive session files... inactive and garbage
> > collection time
> > is denoted by the following php.ini settings:
> >
> > session.gc_probability = 1 ; percentual probability
> > that the
> > ; 'garbage collection'
> > process is
> > ; started
> > ; on every session
> > initialization
> > session.gc_maxlifetime = 1440 ; after this number of
> > seconds,
> > ; stored data will be seen as
> > ; 'garbage' and cleaned up by
> > the
> > ; gc process
> >
> > so where is the setting, using the stock session handler, to relegate
> > the gc process to a cron job ?

>
> session.gc_probability = 0
>


but wont it still try to run sometimes since that setting determines whether
or not the gc will run *every* time ? i would imagine if it was for *any*
time, setting session.gc_probability = 0 would effectively disable the stock
gc.

Then do it yourself in a script called by cron.


it would be nice if you could latch into the one they provide out of the box
and just invoke it via cron..

-nathan

  Réponse avec citation
Vieux 08/05/2008, 08h33   #9
Németh Zoltán
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: [PHP] $_SESSION v.

> On Wed, May 7, 2008 at 2:35 PM, Robert Cummings <robert@interjinn.com>
> wrote:
>
>>
>> On Wed, 2008-05-07 at 14:29 -0600, Nathan Nobbe wrote:
>> > On Wed, May 7, 2008 at 2:22 PM, Robert Cummings <robert@interjinn.com>
>> > wrote:
>> >
>> > On Wed, 2008-05-07 at 16:03 -0400, tedd wrote:
>> > > At 12:34 PM -0400 5/7/08, Robert Cummings wrote:
>> > > >
>> > > >The exception being when it performs cleanup. Cleanup
>> > should be
>> > > >relegated to a cron job.
>> > >
>> > > Rob:
>> > >
>> > > What clean-up?
>> >
>> >
>> > All the inactive session files... inactive and garbage
>> > collection time
>> > is denoted by the following php.ini settings:
>> >
>> > session.gc_probability = 1 ; percentual probability
>> > that the
>> > ; 'garbage collection'
>> > process is
>> > ; started
>> > ; on every session
>> > initialization
>> > session.gc_maxlifetime = 1440 ; after this number of
>> > seconds,
>> > ; stored data will be seen as
>> > ; 'garbage' and cleaned up by
>> > the
>> > ; gc process
>> >
>> > so where is the setting, using the stock session handler, to relegate
>> > the gc process to a cron job ?

>>
>> session.gc_probability = 0
>>

>
> but wont it still try to run sometimes since that setting determines
> whether
> or not the gc will run *every* time ? i would imagine if it was for *any*
> time, setting session.gc_probability = 0 would effectively disable the
> stock
> gc.
>


that setting is the chance (in percents) for the stock gc to run at any
request. so if it is set to 0, it does not have a chance
of course it will try but it always decides not to run

greets,
Zoltán Németh

> Then do it yourself in a script called by cron.
>
>
> it would be nice if you could latch into the one they provide out of the
> box
> and just invoke it via cron..
>
> -nathan
>



  Réponse avec citation
Vieux 12/05/2008, 02h25   #10
Craige Leeder
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: [PHP] $_SESSION v.

I can't see PHP sessions slowing down your site by that amount. As
someone said, it should be no more than a split second. If you are
having that much of a problem with them, then I would say it is either
your implementation, or another determining factor.

I would not, personally, stray away from PHP's GC of sessions. I would
imagine that any third-party concoction could not be any faster. I
would however, check to see how long PHP takes to clean up defunct
sessions, and also monitor how many sessions are lying around at any
given time.

Regards,
- Craige
  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 11h31.


É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,21497 seconds with 18 queries