Re: [PHP] A no brainer...




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
.



Relevant Pages

  • Re: Finally which ORM tool?
    ... the session' method. ... they use the same mechanism as Linq to Sql does: ... Also, if you pass a variable to the query, the value the variable ... q is affected if I change foo AFTER this query and BEFORE execution. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Credit card confirmation?
    ... MySQL was a very simple database before it incorporated the INNODB engine. ... It will obviously be SSL and the session ID etc will ... PHP stores the session when your script ends. ...
    (php.general)
  • grabbing and posting session state data to a query string
    ... modifying the web.config to write to a SQL database, ... The session data appears to be writing correctly, ... I am trying to write the username to the database (to the temp database ... I am looking to extract the session id to place into a query ...
    (microsoft.public.dotnet.general)
  • Re: Finally which ORM tool?
    ... the session' method. ... able to execute the query by itself. ... has at EXECUTION time is used, ... That SHOULDN'T be important, simply because q LOOKS like a declaration, ...
    (microsoft.public.dotnet.languages.csharp)
  • Best way to integrate classes
    ... Have the Session class extend the DB class? ... MySQL connection via $oDB object further in the code. ... function query { ... // Returns a single record as associative array from query results ...
    (comp.lang.php)