note 37952 added to ref.session
| From: | gzink at zinkconsulting dot com | Date: | Wed, 03 Dec 2003 07:57:13 +0000 |
| Subject: | note 37952 added to ref.session | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-61308@lists.php.net to get a copy of this message | ||
A small warning! $_SESSION can be slooowwwww....
I've never heard of this, but it turns out $_SESSION is much slower than any regular array,
even an exact copy of $_SESSION. Copying large amounts of data in/out of $_SESSION is seriously slow
and each access to $_SESSION is noticeably slower than regular arrays.
The lesson I learned? Don't use $_SESSION in loops that run very much. Even copying data from
$_SESSION before the loop won't help a lot if there's a lot of data there due to a delay
that can be pretty hefty, almost equal to working directly on $_SESSION with foreach() and actually
slower than working directly on $_SESSION if you need to put the data back in the array in my
experience. It's better to pass the data another way if possible, i.e. save the SQL query and
re-run, store in a database, etc.
Just a warning for those who may be using this array in medium to large loops or trying to pass lots
of data. I hope it saves you the hours of optimizing I've had to spend!
-Galen
http://www.zinkconsulting.com/
----
Manual Page -- http://www.php.net/manual/en/ref.session.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+37952
Delete -- http://master.php.net/manage/user-notes.php?action=delete+37952&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+37952&report=yes
Search -- http://master.php.net/manage/user-notes.php