Q:

php reading a file and reading data from mysql which one is faster

It's a real php interview question. I know the answer is not just which one is faster. We can answer it in many aspects. Can anyone give me some suggestions please?

A:

files:

reading file: fast
predicting format/codepage: slow, painstaking, error prone
file permissions management
multiple write access not possible
locking mechanism strategy required
parsing file: relatively fast. depending on data complexity
file seek of file in directory with many other files(1000+): extremely slow as the OS will iterate through the file list in directory to find your requested file with a binary search(if you're lucky)
reading not possible when other is writing
threaded fork issues
large filesizes if stored in text
In short: only use files for static data like configuration files. Never for dynamic data

Database:

better management of all of the above
compact storage
fast lookup engine
easy combining of related fact
easy to share access with other machines/programs
rollback mechanisms built in.
Don't use for configuration that remain static.

