1. Language level

  • Use built-in functions, variables and constants to avoid repeated wheel building
  • Use less PHP magic
  • Use the error suppressor @ sparingly
  • Unset unset unset unset unset unset unset unset unset
  • Use less regular expressions (backtracking is expensive)
  • Use single quoted strings as key values to avoid look-up overhead by treating unquoted keys as constants (#define)
  • Avoid repeating operations within the loop
  • Reduce computationally intensive services (using languages such as C)

2. Environmental factors

  • Linux Operating environment

  • disk

Reduce file-like operations

  • The database

  • The cache

Opcache (zend_opcache)

  • Network (optimizing network requests)

Set timeout times: link timeout 200ms, read timeout 800ms, write timeout 500ms Serial request parallelization: CURl_mult_ *() swoole Extension compression PHP interface output: GZIP

  • Use PHP extensions instead of high-frequency logic

Performance overhead: [read/write memory] is much less than [database] is less than [disk] is less than [network]. If necessary, the database, disk and cache can be separated into a separate server.

3. Tools

  • Ab tools

Performance testing tool

  • vld

Opcode viewer tool

  • xhprof

PHP performance analysis tool