Optimize PHP Code
Optimizing PHP Scripts
- Use Native PHP Functions
- Use Single Quotes instead of double quotes
- Use “= = =” instead of “= =”
- Use Appropriate Str Functions - str_replace is faster than preg_replace
- Pass Reference to Function - A function manipulating the reference is faster than those manipulating the value
- Create Classes Only When its Required
- Disable Debugging Messages
- Use Caching Techniques
- Close the Connection
- Reduce Number of Hits to DB
- Frequently Used Switch Cases instead of multi if else
- Use Methods in Derived Classes
- use JSON instead of XML
- Use isset instead of using count( ), strlen( ), sizeof( )
- use echo. echo is faster than print.
- Unset your variables to free memory, especially large arrays.
- require_once() is expensive
- Use full paths in includes and requires, less time spent on resolving the OS paths
- str_replace is faster than preg_replace
- Error suppression with @ is very slow.
No comments:
Post a Comment