5 May 2006
Simple Optimization for PHP and MySQL
Posted by Mikhail Esteves under: LAMP; Tips .
A list of simple tips to optimize PHP and MySQL. For example:
MySql
- MySQL is interpreted from right to left so you should put the most significant limiters as far to the right as possible.
- If you only want one line as a result from the database you should always use LIMIT 1. This way mysql stops searching when it finds the first line instead of continuing through the whole database, only to find that there weren’t any more lines that matched the query.
- Use NOT NULL as default value as much as you can, it speeds up execution and saves one bit.
PHP
- Don’t concatenate when you don’t need to.
- Set the maxvalue for your for-loops before and not in the loop.
- echo is faster than print.