one of reasons why not store even small images in db?
Posted: Sun Jan 08, 2006 1:07 pm
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
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