Optimization of PHP interview questions: php interview questions. PHP interview questions optimization, php interview questions * PHP performance questions * 1. incorrect PHP syntax * 2. use PHP to do what it is not good at * 3. services linked using PHP language are not powerful * 4.P PHP interview questions optimization, php interview questions
* PHP performance issue * 1. incorrect PHP syntax * 2. use PHP to do what it is not good at * 3. services linked using PHP language are not powerful * 4. what PHP itself can't do ** PHP performance problem solving direction * 1. PHP language-level performance optimization (code optimization) * 2. performance Optimization of PHP peripheral problems (linux, mysql, disk, etc.) * 3. PHP language performance optimization (layer c) ** use AB stress testing (-n requests-c concurrency url target pressure test address )*. /AB-n1000-c100 http://www.baidu.com * Request per second the number of requests received per second (the larger the better) * Time per request the time required for a Request (the smaller the better) ** Time php test. php test code execution time ** vld-PHP Opcode View extension * php-dvld. active = 1 -dvld.exe cute = 0 test. php ** PHP code running process **. php (php file)-> parse (scan code, analysis)-> Exprs (saved as a file recognizable by the zend Engine)-> Parser (resolution) -> Opcodes (executable files)-> Exec (execution)-> Output (Output results) * use PHP built-in variables and constants, function * php built-in functions are also different, with low time complexity. in this example, there is a difference between isset () and array_key_exists () * try to avoid using the PHP magic function * to disable the @ error blocker, which will produce additional overhead * use the memory properly and use unset () release unused memory in time * use as few regular expressions as possible * avoid computation in the loop ($ I = 0; strlen ($ str); $ I ++) {} * reduce computing-intensive businesses (php language features make PHP not suitable for large data operations) * be sure to use a string with quotation marks for key values * Reduce File operation memory <
<数据库<磁盘<读写网络数据 * 优化网络:1.设置超时时间 连接超时200ms 读超时800ms 写超时500 2.将串行请求并行化:使用curl_multi_*() ,使用swoole扩展 压缩PHP接口输出:Gzip 好处:client更快获取数据 坏处:额外的cpu开销 PHP缓存复用 时间窗口重叠方法 PHP旁路方案 xhprof (php -ri xhprof)
* PHP performance issue * 1. incorrect PHP syntax * 2. use PHP to do what it is not good at * 3. services linked using PHP language are not powerful * 4. p...