note 37952 deleted from ref.session by didou
| From: | didou@php.net | Date: | Sun, 24 Jun 2007 02:54:07 +0000 |
| Subject: | note 37952 deleted from ref.session by didou | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-127907@lists.php.net to get a copy of this message | ||
Note Submitter: gzink at zinkconsulting dot com
----
[Editors note: I've just benchmarked this, and over a 100 element array the results are as
follows: (average over 10 runs)
Standard Array: 0.102ms
$_SESSION: 0.197
This is in the extremely unlikely case of having to loop through 100 elements in a session variable.
Remember, if you have that many elements in your session, something is wrong.]
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/