I've a web app built in PHP with Zend on a LAMP stack. I have a list of 4000 words I need to load into memory. The words have categories and other attributes, and I need to load the whole collection every time. Think of a dictionary object.
What's the best way to store it for quick recall? A flat file with something like XML, JSON or a serialized object? A database record with a big chunk of XML, JSON or a serialized object? Or 4000 records in a database table?
I realize different server configs will make a difference, but assume an out-of-the-box shared hosting plan, or WAMP locally or some other simple setup.
Especially in the case when small files are read first time, MySQL database is much faster than a pure filesystem. This is probably caused by better caching in MySQL database.
If you are fetching data from SQL and then doing the calculations in PHP over the fetched data its far better to fetch the required result and avoid PHP processing. The time taken to fetch the data in SQL is time consuming but once its done calculations are more over same.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With