What happens, you may experience performance issues:
Improper use of 1.php syntax
2. Use the PHP language to do what it is not good at
3. A service that is connected in PHP language does not give force
4.php of its own short board
5. I do not know the question
General: PHP performance issues not exceeding One-second (general 30%~40%)
PHP Performance Problem Resolution direction:
PHP language-level performance optimization->php performance optimization of peripheral problems (connected services, network environment)->php Language self-analysis and optimization
(PHP language level)
Optimization point: Write less code, use PHP's own ability
Problem: More self-written code redundancy, poor readability, resulting in low performance
Why Low: PHP code needs to be compiled to parse into the underlying language, the process of each request will be processed once, the cost is large
Method: Use PHP built-in variables, constants, functions
Optimization points: PHP built-in function performance advantages and disadvantages
Case Description: PHP built-in functions, there are still differences between the speed
Recommendation: Learn more about the time complexity of PHP built-in functions
Optimize points: Use as few magical functions as possible
Scenario Description: PHP provides a magic function that is poorly performing
Why low performance: In order for PHP programmers to save trouble, PHP language for you to do a lot of
A good way: Avoid using PHP magic functions as much as possible
Optimization point: Error suppressor that generates additional overhead
Actual logic: Before the code starts, set the highest error level, after the end, then reply to set the error level. Add opcode, ignore error
Optimize points: Use memory appropriately
Case Description: PHP has a guaranteed memory recovery mechanism, but please also use memory carefully
Recommendation: Use Unset () to release the non-applicable memory in a timely manner (note: unset () occurs when the logoff is not lost)
Optimize points: Use regular expressions as little as possible
Description: The retrospective overhead of the expression is large, "no diamond do not embrace the ceramic live"
Recommendation: Use string processing functions to implement the same logic
Optimization points: Avoid doing operations within loops
Description: Calculation in the loop will be repeated
<?php$str= "Hello World"; A//strlen ($STR) is placed outside for ($i =0; $i
Optimize points: Reduce compute-intensive business
Scenario Description: PHP is not suitable for intensive computing scenarios
Why? PHP language features determine PHP is not suitable for large data-volume operations
PHP fit Scenario: Fits webserver and backend services, UI rendering
Optimization points: Be sure to use quoted strings for key values
Case Description: PHP will use a key value without quotation marks as a constant, generating the cost of finding a constant
Recommendation: Use quotation marks strictly as key values
--------------------------------------------
(Performance optimization for PHP peripheral issues)-
Operating environment, file storage, database, cache, network
Reduce File class operations
Cost order for common PHP scenarios:
Read and write disks, read and write databases, read and write memory, read and write network data
Read/write Memory <<><><>
Optimize Network Requests
Pit of Network request:
1. Uncertainties in the interface of the other party
2. Network stability
How do I optimize network requests?
1. Set timeout period
A) connection Timeout 200ms
b) Read Timeout 800ms
c) Write timeout 500ms
2. Parallelization of Serial requests
A) using curl_multi_* ()
b) using Swoole extensions
Compressed PHP interface output
Cache Duplicate Compute Content
What happens when the output content is cached?
Multiple requests, the content does not change the situation
Overlapping time window thought
Bypass scheme
Analyze PHP self-analysis and optimization:
Testing with tools
PHP Performance Bottlenecks Workaround:
Opcode cache (last link in code compilation) PHP extension APC does Opcode cache
Supplemental stress test Software instructions for use:
Ab-h
Apache Benchmark (AB) is a stress test software provided by Apache that comes with the beta software when installing Apache servers
Use:./ab-n1000-c100 http://www.baidu.com/
-N Request number-c concurrent Number URL target pressure-measured address
The above content to introduce the simple PHP performance optimization attention point, I hope this article sharing can help everyone.