Storing pictures in sessions?
Moderator: General Moderators
Storing pictures in sessions?
A quick question: Is it good idea to store images in sessions? Are all session variables loaded from session files into memory immediately when script starts? If they aren't then it might be a good idea? If they are, I'll use database instead. I need a good place to store some temporary stuff - many kinds of stuff. I don't want that temporary data to be scattered around in files, database and sessions.
Re: Storing pictures in sessions?
so? waht about php sessions? Are all the session variables loaded from session files into the memory immediately everytime you call session_start?
- John Cartwright
- Site Admin
- Posts: 11470
- Joined: Tue Dec 23, 2003 2:10 am
- Location: Toronto
- Contact:
Re: Storing pictures in sessions?
It is a *very* bad idea to store any binary in the session files. I wouldn't put them in the database either. Both of which cause unneccesary overhead (especially the former).
What is wrong with putting them in a central location on the file system, and if need be, store the meta data in the database.
What is wrong with putting them in a central location on the file system, and if need be, store the meta data in the database.
Re: Storing pictures in sessions?
I know it will cause some overhead, because its a filesystem inside a filesystem, but it's temporary data(max 1-2mb). Files feel a bit messy. Ok, but what about session variables? How are they loaded into memory? I mean if I have a lot of data in sessions and I use only small part of it on every request.
Re: Storing pictures in sessions?
There is no need (ever, i believe) to store image data in a session or in a database. It's already on the server anyways in /tmp.. you can leave it there to be picked up by garbage collection or move it to a permanent location. Reference the file location in the session variable instead.
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
Re: Storing pictures in sessions?
Ok, I'll do that. Storing files in sessions(or in database) was just a random idea. Never done that before. I was just wondering if it was thinkable to store something bigger in sessions. I'll ask again: How is the session loaded? Does php dump whole session into the memory every time or are the necessary session vars loaded only when used?
Re: Storing pictures in sessions?
Here's my guess:
When session_start() is initialized.. the session file (yes it is a flat file) is read and unserialize()'d and it is all loaded into memory. Then all session variables are available throughout the entire script.
That's what I would think, but I have not researched session usage extensively.
When session_start() is initialized.. the session file (yes it is a flat file) is read and unserialize()'d and it is all loaded into memory. Then all session variables are available throughout the entire script.
That's what I would think, but I have not researched session usage extensively.
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
Re: Storing pictures in sessions?
That's correct. If you just unset() the data on the next request there'd be not a lot of extra overhead, but I'm gonna say you should store on filesystem, much better. If you made a re-usable class it wouldn't be as messy as you think it seems.