Wednesday, March 27, 2013

Optimization - PHP, Mysql, Session


Optimize your PHP to Improve Performance
1. Use echo rather than print
2. Reduce variable declaration
3. Don't copy variables for no reason
4. register_globals should be disabled
5. Make sure all inputs are escaped
6. Avoid doing SQL queries within a loop
7. use regular expressions only where it is mandatory
8. Avoid using PHP function inside for()
9. Error Handling
10. Increase the memory size //@ini_set("memory_limit","16M");
11. Use MVC Architecture
12. Use Template System (smarty)
13. Use Caching [ob_start(), ob_get_clean()]
14. Use Output buffering
15. HTML optimize using ob_gzhander
16. Enable compression in php ini
                zlib.output_compression = On
                zlib.output_compression_level = (level) (where level is 1-9)


Session Optimizations
   • Don't use session.auto_start.
   • Do not enable session.use_trans_sid
   • Whenever possible set session.cache_limiter to private_no_expire
   • Assign each user (vhost) its own session’s directory.
   • For large sites consider using session.save_path = "N;/path"
   • If possible avoid automatic garbage collection.


Query Optimization:

              Don’t use “SELECT *”
              Better to use Joins rather than sub-queries
             Unoptimized joins can be VERY slow
             Use LIMIT
             use index meaningful
             confirm you escaped the string correctly
             Use EXPLAIN to find query fast
            Avoid queries in loop

No comments:

Post a Comment