Optimization of test questions on PHP surface

Source: Internet
Author: User
Tags php language

* 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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.