* PHP Performance issues * 1.PHP syntax improper use * 2. Use PHP language to do what it is not good at * 3. The service that uses the PHP language link does not give the force * 4.PHP itself does not do the thing * * PHP Performance Problem Resolution direction * 1.PHP language-level performance optimization ( Code optimization) * 2.PHP Peripheral Problem performance optimization (linux,mysql, disk, etc.) * 3.PHP Language performance optimization (c-tier) * * Use AB pressure test (-N Request number-c concurrent number URL target) *./ab-n1000-c100http://www.baidu.com* Request per second The number of requests received per second (the bigger the better) * Time per request a demand takes a while (the smaller the better) * * Time PHP test.php Test Code Execution Times * * vld-php Opc Ode View Extension * php-dvld.active=1-dvld.execute=0 test.php * * PHP code Run Process * *.php (PHP file)->scanner (scan code, analysis)->exprs (Save as Ze nd engine recognizable files)->parser (parse)->opcodes (executable file)->exec (execution)->output (output) * Multiple PHP built-in variables, constants, Functions * PHP built-in functions are also different, Use less time complexity. Example Isset () and array_key_exists () differences * Avoid using the PHP Magic function * Disable the @ ERROR suppressor, resulting in additional overhead * Reasonable use of memory, using unset () to release unused memory in a timely manner * Use regular Expressions sparingly * avoid doing operations within loops for ($i =0;strlen ($STR), $i + +) {} * reduce compute-intensive business (PHP language features make PHP unsuitable for large data operations) * Be sure to use quoted strings for key values (key) * Reduce file class operations memory << Database < Disk < read and write network data * Optimize network: 1. Set timeout time connection Timeout 200ms read Timeout 800ms write timeout 500 2. Parallelize the serial request: Using curl_multi_* (), Use swoole extension * to compress PHP interface output: Gzip Benefits: Client gets data faster disadvantage: Extra CPU overhead * PHP Cache multiplexing * Time Window overlay method * PHP Bypass scheme * XHPROF (Php-ri xhprof)
Optimization of test questions on PHP surface