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.

No comments:

Post a Comment