Reply to Re: Difference between storing files on folder and in mysql db

Your name:

Reply:


Posted by Jerry Stuckle on 01/09/08 04:05

NC wrote:
> On Jan 8, 8:56 am, missmoo <mor...@gmail.com> wrote:
>> I would like to know what the differences are in terms of security,
>> reliability and resources between storing user-uploaded images in a
>> file or storing them in a mySQL database.
>
> The only significant difference is the DB server load. Since <img
> data="*"> tags are not (yet?) commonly supported by browsers, you need
> a separate instance of an image display script (and a separate
> connection to the DB server) to display each image. So if your Web
> page has 100 images on it, it will require 101 nearly simultaneous
> connections to display itself and the images, as opposed to one
> connection if images were stored in the file system. Granted, image
> retrieval connections would be very short, but at high loads, this
> architecture would be patently inferior to disk-based alternative.
>

Not true. <img> tags are handled identically by the client, whether the
image comes from the database or the file system. The client doesn't
know or care if the image is from a database or not.

> Also, if you use MyISAM tables, storing large images in them will
> bring you to the limit of table file size much more quickly. If your
> average image is 1 MB and your file system's maximum file size is 2 GB
> (there are still some older Linux servers whose file systems have this
> constraint), you will only be able to store about 2,000 images until
> your table exceeds the maximum allowed file size.
>

Few Linux implementations have a 2GB limit any more. Most are at least
4GB, and some implementations are much larger.

Also, the typical image size is *much smaller* than 1MB.

> Additionally, you'll need to make sure that your MySQL server is
> configured with a packet size large enough to transmit the entire
> record, including the image. Up to MySQL 3.23, this limit was 16MB
> for MyISAM tables. As of MySQL 4.0, situation changed; the effective
> maximum length of LONGBLOB is determined by maximum packet size and
> available memory.
>

MySQL easily handles this for you.

>> Our company is starting an image-competition soon, and I am not sure
>> if I should write the php script to insert the binary code into a
>> mySQL database or if I should just store the files in a dedicated
>> folder and the data about them in the mySQL database.
>
> Large image sharing sites invariably stick to the second approach.
> Moreover, images may be stored on separate servers, optimized for
> serving static content.
>

An over-generalization. Many have images stored in the database itself.

> I answered a similar question here a few months ago, take a look:
>
> http://groups.google.com/group/comp.lang.php/msg/e44b33db1a37543b
>
>> Which system should I use? Is there a real difference between the two?
>
> Only at high loads...
>
> Cheers,
> NC
>


--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация