So. I have a table of data, in a MySQL database, eg:
- Artist Name
- Artist Biography
- Artist Age
lets say for example: 100 artists.
Because this data will be modified very rarely, I have created an interface whereby when the data is modified by the administrator using the content management system, the system queries the database, and saves a serialized PHP array of the data as a file on the server.
This file is recreated everytime a new artist is added, say once a week.
On the frontend, when the page is loaded instead of querying the database the page simply includes
the file (using output buffering) and produces the HTML page layout from this object.
Is this a good idea? Is this going to be quicker than having hundreds of users query the database everytime the page loads?
As an extension to this question, if I start to page the data e.g. set a limit on the MYSQL result object to 10 rows, will it be slower to access the whole table as a PHP array and cut that down into groups of 10 – echoing out the relevant section based on the query string?
It probably will be slower. Storing it on the filesystem will require unserialization of the full file even if you need only a small chunk of data.
Never forget: Databases are fast! And if they are not you are missing an index 😉
PS: If you want to increase performance (and do so only if you really need it!) either use APC or even better cache the fully generated page, so it may be served nearly-statically.