NYCPHP Meetup

NYPHP.org

[nycphp-talk] Files or BLOBs??

Hans Zaunere hans at nyphp.com
Thu Aug 26 23:19:04 EDT 2004


> Im planning a web-based application where users upload text files to a
> site where they are stored and can be searched, viewed, edited, etc.
My
> first instinct is to use some database to make indexing and searching
> nice and fast. However, each file can vary from 26K to 35K - and I
think
> this is rather large to store in a column in MySQL so maybe I will
have
> to use files and use MySQL to store meta-data about the file. What do
> you guys consider a good approach for this sort of thing?

Typically it's recommended to store files on the filesystem, with
metadata in MySQL.  There are many reasons for this, and depending on
traffic and filesize they may not be that important, but here are some
general thoughts:

In order to retrieve a file from MySQL, this process has to happen:

-- SELECT query is sent to MySQL, which is processed and a result
returned
-- the entire contents of the file is sent to Apache/PHP, and stored in
a PHP variable.
-- PHP then essentially echo's the file contents through it's own output
mechanism, which in turns then goes through Apache

This process involves a lot of network and memory IO, so it's much less
efficient than sending directly from a filesystem.  That said, in some
environments (like shared hosting, where filesystem permissions can be
troublesome) keeping everything in MySQL could make sense.

H




More information about the talk mailing list