SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Enthusiast
    Join Date
    Apr 2007
    Posts
    48
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question Advantages of serializing objects in sessions?

    I was playing around with objects and sessions today, and I noticed that an object can be directly stored into a session without having to manually serialize it, and it works perfectly fine. Why do so many people recommend serializing objects when they work fine without being serialized? Am I missing some important concept? Thanks in advance.

    * I was using php 5.2

  2. #2
    SitePoint Wizard silver trophy kyberfabrikken's Avatar
    Join Date
    Jun 2004
    Location
    Copenhagen, Denmark
    Posts
    6,157
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by chobo View Post
    Why do so many people recommend serializing objects when they work fine without being serialized?
    Because they don't know better.

    I think some of the confusion stems from the fact, that PHP uses serialize to persist the session between requests. This means that a lot of places in the manual, serialize and sessions are mentioned together, and people just assume, that you need to do it manually.

  3. #3
    SitePoint Enthusiast
    Join Date
    Jun 2006
    Location
    /USA/Kentucky/Richmond/
    Posts
    27
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Just remember that it is important to keep as little data in the session as possible. On each request that data must be requested, unserialized, objects instantiated/initialized, serialized, and stored (either filesystem, DB, or RAM).

    It might not matter very much if the site or application is hosted on a single dedicated server with relatively low traffic but the above is very significant on clustered platforms with high traffic.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •