I’m currently working on a website in PHP, and I’m wondering what the best practices/methods are to reduce the time requests take. I’ve build the site in a modular way, so a page would consist of a number of modules, and each of these would need to request information.
For example, I have a cart module, that (if a cart is set) will fetch the cart with the id (stored in a session variable) from the database and return its contents. I have another module that lists categories and this needs to fetch the categories from the database.
My system is built with models, and each model might also make a request, for example a category model will make a request to get products in that category.
For those interested, im running the application on Windows Server 2003 with IIS at the moment, but i am hoping to change to linux in the near future. I know this is a broad subject, im just curious about what to look out for and tool to use to help with the load., the answers so far have been very helpful.
Your high-level approach sounds reasonable, although it would be helpful to weigh such an approach against your actual code, data, and environment. That said:
A quick and easy way to make your code run even faster is to use a tool such as eAccelerator which will cache compiled PHP scripts. That way when a second request comes in the script does not have to be compiled a second time, which improves performance.
If you are developing a site with a large amount of users, you might consider caching data from the database, using a tool such as memcached.