in PHP, which is faster - reading a file or a database call? in PHP, which is faster - reading a file or a database call? database database

in PHP, which is faster - reading a file or a database call?


If you're using APC (or similar), your fastest result is probably going to be coding the word list directly into a PHP source file and then just require_once()'ing it.


In an ideal system I would say memory (memcached), disk and database. But depending on setup the database could be on several occasions faster than disk because the result could stick in the query cache.

It all depends on the environment; and if it's that critical, you should measure it. Otherwise place it where you think it is more accessible.


I'd place it in a file that can be cached, saving you a lot of unnecessary database calls on a (or maybe even every?) page load. How you store it doesn't really matter, whatever works best for you. Speed-wise, 4000 words shouldn't be a problem at all.

For translations in projects I work on I always use language files containing serialized php-data which is simply easy to retrieve:

$text = unserialize(file_get_contents('/language/en.phpdata'));