On Oct 14, 2006, at 10:00 AM, Tony Di Croce wrote:
I think that the cost of de-serializing a session stored in files
should be significantly LESS than the cost of doing so through a
database, for the following reasons:
1) The db will need to parse querys. Not an issue for files.
2) The session ID will tell PHP what file to open in O(1).
3) The entire session needs to be de-serialized, not just some
portion of it. The database is optimized for returning subsets of
all the data.
Sorry Tony, I should have been more clear. I already know that
storing session data in MySQL is faster than storing it in files. I
know that goes against what you're saying, but there are some
examples if you Google "PHP MySQL session performance". One of the
more interesting examples is http://shiflett.org/articles/guru-speak-
jan2005. PHP session management defaults to files because it's more
portable and the performance difference doesn't matter for small
sites with few concurrent users. MySQL also provides better
scaleability and security for session data.
On Oct 14, 2006, at 2:51 PM, Larry Garfield wrote:
It depends on what your data is.
Is your data basic (a few elements in a linear array) or complex (a
deeply
nested multi-dimensional array or complex object?) Deserializing a
complex
data structure can get expensive.
Is your data built by a single simple query against the database, a
single but
very complex query with lots of joins and subqueries, or a bunch of
separate
queries over the course of the program? A single SQL query for
cached data
is likely faster than lots of little queries.
Is your data something that's going to change every few seconds,
every few
minutes, or every few days? Caching something that will change by
your next
page request anyway is a waste of cycles.
Is your data needed on every page load? Putting a complex data
structure into
the session if you only need it occasionally is a waste of cycles.
You're
better off rebuilding it each time or implementing your own caching
mechanism
that only loads on demand.
There is no general answer here.
Good points Larry. I have to look back, but I think we were
originally talking about basic user data. ie. the user logs into the
site and we store their login information and access rights in a
session. That seems like basic enough information that it's better
to just store the user id in session data and grab the rest of their
information from the db - not much of a difference in performance,
plus you end up avoiding stale data. Anyway, I like your distinction
between simple and complex objects.
-Ed
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php