SESSION memory limit?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • nino
    Junior Member
    • Feb 2005
    • 3

    #1

    SESSION memory limit?

    Hi all,

    Last night i was building a simple shopping cart. Im new to PHP so i was just doing a simple session based one. I stored my products into a session array so that every page could have access to them. Then i had a few other session variables such as total num of products, price, category selected.. etc.. in total i had about 10 variables + a two dimensional array which had all the product though there were only 5. It was 2D because each product then had a few attributes, like price, id, description, category and a couple of others.. not that much stuff. The products were added 1 by one, line by line.

    Then i came to the point when i tried to add a new session variable, i recieved no error but i could not print the variable or have it show up anywhere... tried and tried with no luck. It wasnt till i deleted one of my early variables and made it a local variable that suddenly my new variable worked. I didnt get any sort of error before or after.

    I have a news script (cute news) running as well (though not on the same page) but it is not session based, but cookie. I assume because i didnt edit it and i saw that there was an option for session based news and the default was cookie based.

    Anyway, does anyone know if i can somehow check memory usage, or what not because 10 variables + an array cant be that much of a drag on resources and i dont understand why i hit that... no more variables limit.

    Thanks a lot in advance.
  • Buddha
    Senior Member
    • Mar 2004
    • 825

    #2
    Are you using the the default session.save_path which is set to /tmp? /tmp is cleaned out (very) regularly so it's a lousy place for session variables. Creat your own folder for sessions and use session_save_path() to tell PHP where you want them saved
    Last edited by Buddha; 02-10-2005, 12:25 PM.
    "Whatcha mean I shouldn't be rude to my clients?! If you want polite then there will be a substantial fee increase." - Buddha

    Comment

    • nino
      Junior Member
      • Feb 2005
      • 3

      #3
      Hum, yeah i am using the default, i will try and switch it and see how that works. I do not understand though why then the other variables would work while that last one would not, because that was not the only session variable being used on that page at that time. If the temp folder was cleaned it would clean all of them, right?

      Comment

      • Buddha
        Senior Member
        • Mar 2004
        • 825

        #4
        Originally posted by nino
        If the temp folder was cleaned it would clean all of them, right?
        Not necessary, could be cleaning them out by time stamp or some other criteria. I don't know the specifics though. However, setting up your own session folder should fix the problem. It's also more secure too as /tmp is available to everyone on the server ... not a good place for shopping cart data.
        "Whatcha mean I shouldn't be rude to my clients?! If you want polite then there will be a substantial fee increase." - Buddha

        Comment

        • nino
          Junior Member
          • Feb 2005
          • 3

          #5
          I see. Ok so for general knowledge. What should i "technically" be limited by when it comes to session variables. Memory alloted by dathorn? If so, where can i find out how much that is. I can check all the contents of my SESSIONS variables by doing print_r($_SESSION); i assume so that i can see if anything is in there that is not supposed to be.

          Comment

          • Buddha
            Senior Member
            • Mar 2004
            • 825

            #6
            What should i "technically" be limited by when it comes to session variables. Memory alloted by dathorn?
            Your limits will depend on a lot of factors but memory is just one. Traffic and size of your sessions variables are probably bigger factors. Your session variables could be, just for sake of demostration, 1MB each taking up all available memory in your account under very low traffic (like when your developing a site) this might not even be a problem. However, under normal or high traffic you would be eating up a lot processing power and whacking the heck out of the hard drive.

            Keeping the session variable size as small as possiable is a good practice for getting the most out of your resources. Admittedly not easy when your developing a shopping cart. It's very tempting to put everything in the session variables. Personally I try to put data I use on every page in session variables. Cart data I would put in the database and access when needed, such as when adding or delete items.
            "Whatcha mean I shouldn't be rude to my clients?! If you want polite then there will be a substantial fee increase." - Buddha

            Comment

            Working...