There are two options:
1 - Store the path in a DB field, and upload the image to that path on the web server.
2 - Store image in a BLOB field in the DB and query the DB whenever I need to display the image.
My application will be storing many thousand images. The web server is Apache, the DB is MySql and the PL is PHP, naturally. My primary concerns are the obvious, space and speed. I am willing to compramise on the space in order to conserve speed.
Which option is better and why?
Thanks
--
Maximus
To Blob or not to Blob, that is the question?
Moderator: General Moderators
-
kettle_drum
- DevNet Resident
- Posts: 1150
- Joined: Sun Jul 20, 2003 9:25 pm
- Location: West Yorkshire, England
...
Hmm i always just store the path to the image, but ive never really been concered about speed as ive only stored a few images at a time.
I guess the best thing for you to do would be to do some benchmark tests to see which is faster and which uses the least system resources.
I guess the best thing for you to do would be to do some benchmark tests to see which is faster and which uses the least system resources.
-
fractalvibes
- Forum Contributor
- Posts: 335
- Joined: Thu Sep 26, 2002 6:14 pm
- Location: Waco, Texas
I have done both, and would think it depends upon your situtation.
Option 1 may be the best idea, if management won't change their mind every week where they want the images stored.
Option 2 the better idea if you might need to get to them from multiple applications on different servers that might not be able to see each other's file systems or be separated by firewalls, etc. in such a way as to not be accessible. An example might be where you have photos - certain employees, salesmen, whatever that need to be equally accesible from your Intranet and also from the Internet. Do you replicate and keep all that in sync or simply store in a DB both can get to?
I cannot percieve any difference in speed, in human terms - both are very fast. But a lot depends on other network and database optimizations also....
Phil
Option 1 may be the best idea, if management won't change their mind every week where they want the images stored.
Option 2 the better idea if you might need to get to them from multiple applications on different servers that might not be able to see each other's file systems or be separated by firewalls, etc. in such a way as to not be accessible. An example might be where you have photos - certain employees, salesmen, whatever that need to be equally accesible from your Intranet and also from the Internet. Do you replicate and keep all that in sync or simply store in a DB both can get to?
I cannot percieve any difference in speed, in human terms - both are very fast. But a lot depends on other network and database optimizations also....
Phil
-
pootergeist
- Forum Contributor
- Posts: 273
- Joined: Thu Feb 27, 2003 7:22 am
- Location: UK
If you are only showing one image per page then you could use blob field selects, though I would reccomend against it.
If your default max_active_connections is about 300 then you might be thinking of running a persistent connection for every active session and hoping that no more than 300 people access an images page concurrently.
Remember that you cannot just output the binary into an img tag (well, you can for images below 1kb with some tweaks), you would need to call a getter script - eg <img src="img_grabber.php?img=1234132" /> - now, every time that script is called it needs an open connection and a select - every time for every page view.
Alternatively just store the path and sit back confident that your application can handle as many requests as the server can - confident that it isn't limited by database access limitations.
Yup, I reccommend the first option.
If your default max_active_connections is about 300 then you might be thinking of running a persistent connection for every active session and hoping that no more than 300 people access an images page concurrently.
Remember that you cannot just output the binary into an img tag (well, you can for images below 1kb with some tweaks), you would need to call a getter script - eg <img src="img_grabber.php?img=1234132" /> - now, every time that script is called it needs an open connection and a select - every time for every page view.
Alternatively just store the path and sit back confident that your application can handle as many requests as the server can - confident that it isn't limited by database access limitations.
Yup, I reccommend the first option.