Page 1 of 1

one of reasons why not store even small images in db?

Posted: Sun Jan 08, 2006 1:07 pm
by newmember
Hi

I need your opinion or advice on following scenario:

I'm storing thumbnails (~3kb) in database but original image(~200-500kb) are stored in file system.
When i want to display images, first i display thumbnail which links to large original image.
For minimizing db queries i'm doing this in following way:

1) i grab all thumbnails, 20-30 at once, with single query.

2) then i store them in $_SESSION['images'] array

3) script generates link that looks something like: <img src="get_image.php?k=2"> where 2 is index of that image in $_SESSION['images'] array.

get_image.php simply sends out the image according to given k


so with this approach i do only one db query per page view but at the same time script fills $_SESSION
with tens on kb of data.
What even worse is that when many users access pages with images $_SESSION will get larger and larger and probably not what i want :?

alternativly i could query db directly for each image request...but this seems even worse that first approach

so, after some thinking i see that there are 2 last approaches...

first is obvious one is just store thumbnails in file system and probably that what i'm going to do...

as last approach i thought about implementing some cache schemas...
so what really interesting is whether it is possible to improve the situation using cache files?

what do you think guys?
thanks

Posted: Sun Jan 08, 2006 1:45 pm
by Weirdan
as last approach i thought about implementing some cache schemas... so what really interesting is whether it is possible to improve the situation using cache files?
It's certainly possible... but why would you 1) fetch your thumbnail from the db and store it to filesystem and 2) then serve it to the client? It seems logical to get rid of the first step altogether.

Posted: Sun Jan 08, 2006 1:54 pm
by newmember
It's certainly possible... but why would you 1) fetch your thumbnail from the db and store it to filesystem and 2) then serve it to the client?
yes that would be definitly better that storing in session... :idea: i have to think about it more
what yo actually saing is "use cache file"

Re: one of reasons why not store even small images in db?

Posted: Sun Jan 08, 2006 1:56 pm
by onion2k
So you're storing 20 - 30 * 3kb in the session .. approx 75kb then .. and every time a user views a page that session file is being opened and parsed by PHP .. So you're parsing 75kb of data on every page viewed in order to save .. umm .. what exactly?

Posted: Sun Jan 08, 2006 1:59 pm
by newmember
So you're parsing 75kb of data on every page viewed in order to save .. umm .. what exactly?
as i explained.. instead making 20-30 separate db queries for each image

Posted: Sun Jan 08, 2006 2:08 pm
by Weirdan
newmember wrote: what yo actually saing is "use cache file"
what I'm actually saying is "don't store images into database"

Posted: Sun Jan 08, 2006 2:11 pm
by newmember
what I'm actually saying is "don't store images into database"
yes, i hoped you'll say this :D

thanks.

Posted: Mon Jan 09, 2006 3:02 am
by onion2k
newmember wrote:as i explained.. instead making 20-30 separate db queries for each image
Store the filenames in the session then if you must. Personally .. I see nothing wrong with 30 db queries. Some of my sites query MySQL hundreds of times a second. It's not a problem.