high priority
- Turn on apache's mod_deflate
. it will reduce the data to transfer up to 80%.ther's a CPU cost, thats why dfault is compression 6 over max 9.
AddOutputFilterByType DEFLATE application/javascript text/css
- Install APC to increase performance by 25-100% by removing compile times
- sending gz-encoded data to web browsers that support compressed web pages via ob_gzhandler()
- Do use error_reporting (E_ALL); during debug.
- Profile your code. A profiler shows you, which parts of your code consumes how many time. The Xdebug debugger already contains a profiler. Profiling shows you the bottlenecks in overview
marginal gains
filesystem:
- require_once() is expensive
- Use full paths in includes and requires, less time spent on resolving the OS paths.
- Do use full file paths in production environment over basename/fileexists/open_basedir to avoid performance hits for the filesystem having to hunt through the file path. Once determined, serialize and/or cache path values in a $_SETTINGS array. $_SETTINGS["cwd"]=cwd(./);
- Do use require/include over require_once/include_once to ensure proper opcode caching.
- Do serialize application settings like paths into an associative array and cache or serialize that array after first execution.
objects:
- If a method can be static, declare it static. Speed improvement is by a factor of 4.
- Unset your variables to free memory, especially large arrays.
- Avoid magic like get, set, __autoload
loops:
- Set the maxvalue for your for-loops before and not in the loop.
- Do use foreach for looping collections/arrays.
- Do not use functions inside of for loop, such as for ($x=0; $x < count($array); $x) The count() function gets called each time.
strings:
- echo is faster than print. Use echo's multiple parameters instead of string concatenation.
- Do use single quotes over double quotes.
- See if you can use strncasecmp, strpbrk and stripos instead of regex
- str_replace is faster than preg_replace, but strtr is faster than str_replace by a factor of 4
etc:
- Error suppression with @ is very slow.
- Close your database connections when you're done with them
- If you need to find out the time when the script started executing, $_SERVER['REQUEST_TIME'] is preferred to time()
- Do use ctype_alnum,ctype_alpha and ctype_digit over regular expression to test form value types for performance reasons.
- Do use POST over GET for all values that will wind up in the database for TCP/IP packet performance reasons.
- Do use PDO prepare over native db prepare for statements. mysql_attr_direct_query=>1
- Do NOT use SQL wildcard select. eg. SELECT *
- Do set Apache allowoverride to "none" to improve Apache performance in accessing files/directories.