This is a guest post by Elvis Ciotti of phpntips.com.
Why Optimise your Application
Except for some small websites with static pages, any dynamic website or application exposed to the public should be always be properly optimised; at least by caching the data retrieved from the database.
A site not optimised and not cached could saturate the host server resources and bring it to its knees – Argh!! All the other applications will then be not available, except if there is a resource control on single applications until either you or your systems administrator has had the opportunity to both investigate and correct the issue.
But I’m not a high traffic website! Well a little traffic does not mean you are safe either. A spider or robot, from Google, Bing etc., could easily saturate the server resources when fetching our pages with thousands of request in a few seconds. So, please, address this issue!
How to Optimise your Application
When optimising a site you must consider:
- Either on disk or in-memory, of the data retrieved from the database and other sources, such as an RSS feed
- Optimise database queries:
- Select the best column types – don’t use a text when a varchar will do
- Add indexes when needed – and ensure your queries use them properly
- Avoid joins when possible – MySQL is not as optimised towards them as, say, Oracle or PostgreSQL
- Denormalise the database schema – if it helps to make the most common queries faster
- Profile the code and find relevant bottlenecks
- Optimise the bottleneck
- Profile again
- Use an OpCode cache/optimiser – when the language is interpreted like PHP
- Consider caching the HTML output of the page:
- If you can, cache the entire page
- If you can’t, optimise as much as you can and try and avoid the PHP interpreter entirely
PHP and Zend Framework Optimisation
I personally work with the LAMP stack and Zend Framework. Through the following links, you will find more details about how to optimise PHP applications, with specific tips for Zend Framework applications
If you want to read more by Elvis, check out his blog: phpntips.com.
If you liked what you read and would like to see more, please retweet it, or give it a like on facebook or even give it some digg love. And we always value you feedback and comments.
till next time,