Wednesday, September 5, 2018

Optimize PHP Code

Optimizing PHP Scripts 


  1. Use Native PHP Functions 
  2. Use Single Quotes instead of double quotes
  3. Use “= = =” instead of “= =”
  4. Use Appropriate Str Functions - str_replace is faster than preg_replace
  5. Pass Reference to Function - A function manipulating the reference is faster than those manipulating the value
  6. Create Classes Only When its Required
  7. Disable Debugging Messages
  8. Use Caching Techniques
  9. Close the Connection
  10. Reduce Number of Hits to DB
  11. Frequently Used Switch Cases instead of multi if else
  12. Use Methods in Derived Classes
  13. use JSON instead of XML
  14. Use isset instead of using count( ), strlen( ), sizeof( )
  15. use echo. echo is faster than print.
  16. Unset your variables to free memory, especially large arrays.
  17. require_once() is expensive
  18. Use full paths in includes and requires, less time spent on resolving the OS paths
  19. str_replace is faster than preg_replace
  20. Error suppression with @ is very slow.

Optimize Apache Web Server

Boost the Performance of Your Apache Web Server

  1. Always keep Apache updated to its latest version
  2. Remove Unused Modules
  3. use cache
  4. Put Cache on separate disk
  5. Utilize mod_gzip
  6. Set KeepAlive on and then set KeepAliveTimeout and KeepAliveRequests
  7. Do Not set KeepAliveTimeout too high
  8. Allow symlinks
  9. Avoid Wildcards in DirectoryIndex
  10. use CDN