Apache and PHP performance tips, tricks and what I call database buffering
I’ve found a couple useful web sites to help tune Apache with PHP on web servers.
phpLens has a pretty detailed page on the subject that hits everything pretty well.
For the most part I agree with everything this page says.Â I do have a few other suggestions though.
Web server or module level PHP accelerators seem ideal for speeding up the performance of php scripts.Â Though the 6th suggestion, I would debate whether caching pages in the PHP level is faster or not.Â Libraries like Smarty are great for templating your pages but they have their limits.Â If you are hosting a web site with constantly changing dynamic content, the caching built into Smarty is minimal at best.Â Granted that your original PHP script was well written, the cached Smarty version technically can’t re-optimize your database queries, which is most likely the source of any delays with a dynamic web page.
One suggestion that is missing from the post is optimizing your SQL queries and methods how you select the data.Â phpLens mentions the concept of output buffering.Â What I am about to explain is similar and should be deployed together.Â First and for most, when you are working with a result set of data from a database, loop through all the data and store it in variables as quickly as you can and free up that queries resource.Â This will use the time you are connected to the database as efficiently as possible and prevent you from accidentally creating nested queries.Â Since this practice is very similar to output buffering, perhaps we should call it ‘database buffering’.Â The database may still buffer data as well, but your script knows better than the database what to do with the selected data and your script definitely knows what queries are going to happen next.Â Database buffering practices just make sense.
I would also recommend testing your web sites for security issues.Â Check out Nikto, it is a pretty powerful web server scanner that looks for vulnerabilities and security issues.