How To Optimize MySQL & PHP For Better Performance

Posted on December 9th, 2012

Posted By Rishabh Jain | Comments

php-optimization tips

In previous article we told you various steps for optimizing the Apache Server. Now its time to optimize your MySQL database as well as your PHP to enhance your performance. So below are some useful tips for optimizing the MySQL and PHP which may help you :-

Tips For Optimizing The MySQL :-

First of all you must optimize your database queries follow the below tips to optimize the queries and speed up your MySQL database :-

 

1.Set up indexes on columns used in the WHERE clause, to speed up evaluation, filtering, and the final retrieval of results. To avoid wasted disk space, construct a small set of indexes that speed up many related queries used in your application.

 

2.Minimize the number of table scans in your queries, particularly for big tables.

 

3.Avoid transforming the query in ways that make it hard to understand, especially if the optimizer does some of the same transformations automatically.

 

4.Adjust the size and properties of the memory areas that MySQL uses for caching.

 

5. With the efficient use of the InnoDBbuffer pool, MyISAM key cache, and the MySQL query cache, repeated queries run faster because the results are retrieved from memory the second and subsequent times.

 

6.Make your application more scalable. Scalability means that your application can handle more simultaneous users, larger requests, and so on without experiencing a big drop in performance.

 

7.Speed of your query might be affected by other sessions accessing the tables at the same time.So there is need to pay attention of your locking issues.

 

8.Keep table statistics up to date, so the optimizer has the information needed to construct an efficient execution plan.

 

9.Minimize the number of table scans in your queries, particularly for big tables.

 

10. Adjust your indexes, WHERE clauses, join clauses, and so on.

 

Tips For Optimizing PHP :-

 

PHP Code is plays very important role in the overall performance of your website. If your PHP code is not optimized then it will affect your website’s speed and overall performance. So PHP Optimization is must in order to achieve maximum performance. Follow the below tips suggested by Edenhost and achieve maximum performance :-

 

1. Upgrade your version of PHP as The team of developers who maintain the PHP engine have made a number of significant performance improvements over the years.

 

2. Use Caching because Making use of a caching module, such as Memcache, or a templating system which supports caching, such as Smarty, can help to improve the performance of your website by caching database results and rendered pages.

 

3.Set and call the name property directly,it can run up to 100% faster, as well as saves development time.

 

4. Use Echo instead of Print, Echo is better than Print.

 

5.If the method can be static,Declare it static, It improves the speed.

 

6.Use functions outside of loop. Otherwise function gets called each time and slows down the performance.

 

7.Unset your variables to free memory, especially large arrays.

 

8.It’s better to use switch statements than multi if, else if statements.

 

9. $row[‘id’] is 7 times faster than $row[id]

 

10. Don’t forget to Close your database connections when you’re done with them.

 

So these are some essential tips offered by Edenhost which you should apply to your website in order to achieve maximum performance. If you face any problem, Contact our support team.



About Rishabh Jain - Hello, I am rishabh Jain CEO Of Eden Web inc.