Forum Moderators: coopster

Message Too Old, No Replies

display images with php+mysql or with regular file access

what way of showing images is faster and uses fewer resources

         

zRonin

12:54 pm on Jun 8, 2005 (gmt 0)

10+ Year Member



Here are the two options:

1) using a mysql database to look up an image name from an ID and displaying the found image by accessing its location on the fileserver without opening the image and displaying it thru php. (Just redirecting the browser to the image)

mysql table:

¦int:ID¦char:Name¦

2) using a mysql database to look up an image from an ID and displaying that image thru the PHP functions (or maybe just sending a binary file)

mysql table:

¦int:ID¦medblob:Content¦

I have heard some statistics that storing the image in a mysql database is actually faster by 1 second per 1000 images, but I figured it is always better to have a second opinion.

Sanenet

12:57 pm on Jun 8, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I think that if you're that worried about performance options you should think about upgrading to oracle. :)

Me, I'd go for calling the file, if only to save faffing about with all the putting the images into the database in the first place.

zRonin

1:17 pm on Jun 8, 2005 (gmt 0)

10+ Year Member



I am not familiar with oracle, isnt it a database? How would that help me? - And were you just joking or would this be possible.

Also, about putting the file into the database, I would have to put the location in the database anyway, so 3-4 more lines of code reading in the file?

I am mainly interested in the performance side of this problem.

dcrombie

1:18 pm on Jun 8, 2005 (gmt 0)



The method I use is to name the image files based on the database id.

eg.

/photos/large/123.jpg 
/photos/small/123.jpg
/photos/thumb/123.jpg

If you need to preserve the filename/filetype then store that information in the database and use a passthru command.

There's no way I would consider storing images actually in the database. Just considering how many ways that could go wrong gives me a headache ;)

Sanenet

1:20 pm on Jun 8, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Oracle is what you use when you have a million visitors a day to your site. It was a joke. :)

I would have thought that it would be less processor intensive to call the file rather than have to render it from the database. Why don't you carry out some tests?

I remember that a friend of mine - a few years ago now - was storing his images in MySql db, but swapped over to files because the strain was too much for his server to handle. However, MySql has come on since then.

tomda

1:30 pm on Jun 8, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The method I use is to name the image files based on the database id.
eg. /photos/large/123.jpg /photos/small/123.jpg /photos/thumb/123.jpg

zRonin, just to say that you better use unique-encoded id instead of incremented the value.

My 2cents
Cheers

dcrombie

1:34 pm on Jun 8, 2005 (gmt 0)



The method I use is to name the image files based on the database id.
eg. /photos/large/123.jpg /photos/small/123.jpg /photos/thumb/123.jpg

zRonin, just to say that you better use unique-encoded id instead of incremented the value.

Why?

zRonin

1:35 pm on Jun 8, 2005 (gmt 0)

10+ Year Member



Ok, I think I will go with a database for the information and direct file access for the file. I can't get around using a database one way or another because each file has lots of information to store with it like descriptions, the owner, time uploaded, times downloaded, etc.

zRonin

1:37 pm on Jun 8, 2005 (gmt 0)

10+ Year Member



zRonin, just to say that you better use unique-encoded id instead of incremented the value.

Sorry about the double post, but he didnt post until after I started mine and I cant edit.

Good idea. I can add some sort of timestamp to each file like I did for another project. (i.e. name[timestamp%1000].ext)

tomda

6:18 am on Jun 9, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



DrCrombie: encoding filename has no use if all your pictures are public. But if you want to have for example some pics to be seen by members only, then encoding filename is great because user can't guess the filename of your pic (and typing it in the URL bar).