Sunday, January 27, 2013

Optimise your tables

Optimise your tables

The SQL statement "OPTIMIZE TABLE table " lets you specify a table (or several tables, with commas in between) that you would like MySQL to optimise. Notice the spelling is with a Z in the statement. By "optimise", I mean tables that have had a lot of changes made to them since they were created - lots of rows added/deleted/edited, etc; especially if the table uses varying length fields like VARCHARs and TEXTs. OPTIMIZE TABLE instructs MySQL to basically defragment the table to make it faster to read and write from.

Avoid mod_access if you can

Apache has a special module, known as mod_access, that allows you to place files called .htaccess in directories and have them specify authentication information required for that directory. While this is a nice and easy way to solve the issue of stopping unauthorised users access places they shouldn't, it's not very fast.
Mod_access works by looking for a .htaccess file in the directory requested by the user. If it finds it, it loads it and uses it. If not, it goes to the parent directory and looks there. If there's nothing there, it goes to the parent directory of the parent directory, then to the parent of the parent of the parent, etc, until it can go no further. If you don't actually use .htaccess files, all this checking is pointless - and it needs to be done every time a page is requested on your server.
The best way to get around this problem is just to disable mod_access outright, but if you simply have to have it then the only thing I can recommend is that you don't have too many subdirectories - if you have a maximum of two subdirectories, there are only two checks per request, but if you have six subdirectories (such as /html/newsite/images/gnome/highquality/zipped) then the workload is tripled!

Compress your output

The solution is to enable output buffering, and to use gzip compression for the buffers. Output buffering, if you were unaware, makes PHP store up its data into one big chunk, then send it to Apache all at once. Because all the data is kept together and sent all at once, PHP is able to compress it using gzip compression, which will generally reduce the content to around 33% of its original size (that is, 1MB will become 300KB).

garbage collection

use unset(), mysql_free_result(),

php performance Pre-increment where possible

Take advantage of the fact that PHP allows you to post-increment ($i++) and pre-increment (++$i). The meaning is the same as long as you are not writing anything like $j = $i++, however pre-incrementing is almost 10% faster,

Php performance loops

Get your loops right first

 A good rule of thumb to keep in mind is "90% of your scripts execution time is taken up in 10% of the code" 

 

for ($i = 1; $i < count($myarr); ++$i) {
    
// }
 
Never right Such type of code . It can be make site very slow.
 
 

 

php performance

Hoare's law tells us "inside every large program is a small program struggling to get out", so you should consider chopping out blocks of code that are outdated, outmoded, replaced, or irrelevant.

When dealing with performance benchmarking, however, you need to be wary - it has been said that "premature optimisation is the root of all evil".


1     Banchmarking
2.    Jmeter
3     code caching
4.    php-performace-with-memecache
5.    php-performance-caching
6.    loops
7.    use preincrement operation
8.   Listen to all errors, big and small
9.    Keep upto date your php version
10  compress-your-output
11. Use persistent connections
12. avoid-modaccess
13 . Optimising your SQL
14 . Optimise your tables
15 .Select as little data as possible
16 Load data intelligently
17 . Use innobdb
18.  Spot slow queries
19.perform-joins-carefully.html
20 Index your data
21 .Increase your buffers
22. PHP Accelerators
23 .advantages of UPDATE LOW_PRIORITY and INSERT DELAYED INTO