Hi,
With my current project, there is potential for some large volume of users uploading images to their account. I've thought about doing this 3 different ways, but which way would provide best performance?
1. Store in blob in MySQL
2. Upload File with random unique filename, and storing filename in DB.
3. Save the original filename in the DB, and save the file itself following the primary key.
Ex. original filename is james.jpg but is renamed to 5.jpg because it's ID is 5.
I'm leaning towards the DB, because it could keep robots from downloading all my images, but will I take a significant performance hit storing them in blobs?
Josh
Databases and Images - Performance Question
Moderator: General Moderators
- feyd
- Neighborhood Spidermoddy
- Posts: 31559
- Joined: Mon Mar 29, 2004 3:24 pm
- Location: Bothell, Washington, USA
keeping them in the database wouldn't keep a robot from downloading them, it'd just eat more processing time requirements.
2 & 3 are both good solutions, I'd only do 1 as a last resort.. (but I'd move to a better host before that
)
2 & 3 are both good solutions, I'd only do 1 as a last resort.. (but I'd move to a better host before that
Last edited by feyd on Thu Aug 18, 2005 7:27 pm, edited 1 time in total.
- raghavan20
- DevNet Resident
- Posts: 1451
- Joined: Sat Jun 11, 2005 6:57 am
- Location: London, UK
- Contact:
feyd, I am working with a Products_tbl where each product has an image.
Anyway, each image I upload to the server I create an entry in Images_tbl, image_id and image_path.
I assign the image_id to the product_id and retrieve the filepath to display the image.
It would be easier I think if all the images are recorded in the database and may be have a admin page which list all images and I think unlink($image_path) would delete it.
do you think its a good way of doing it???
Anyway, each image I upload to the server I create an entry in Images_tbl, image_id and image_path.
I assign the image_id to the product_id and retrieve the filepath to display the image.
It would be easier I think if all the images are recorded in the database and may be have a admin page which list all images and I think unlink($image_path) would delete it.
do you think its a good way of doing it???
- feyd
- Neighborhood Spidermoddy
- Posts: 31559
- Joined: Mon Mar 29, 2004 3:24 pm
- Location: Bothell, Washington, USA
very often, storing images in a database requires:
- more time to fully load a page
- more memory consumption the database server has to deal with
- more memory consumption php has to deal with (database server has to load data into memory and transfer it into php)
- more space consumed by a backup
- DBMS may be faster and more efficient at storing
- backing up the database backs up the images
- the data may be more secure, being outside the filesystem
- raghavan20
- DevNet Resident
- Posts: 1451
- Joined: Sat Jun 11, 2005 6:57 am
- Location: London, UK
- Contact:
One other reason, but its quite rare:feyd wrote: reasons for it:
- DBMS may be faster and more efficient at storing
- backing up the database backs up the images
- the data may be more secure, being outside the filesystem
You have a User Defined Type in your database to store images that lets you do image-level comparisons in the Database.
For instance in PostGreSQL and many commercial DBMS's you can define an "Image" type, and you can define a "sameness" measure that lets you search for images that are similiar to each other, using efficient (typically C code) in the DB. or in some GIS systems you can have it "find overlapping regions" for mapping, etc