PHP Language performance optimization optimization what?
As shown, PHP directly executes the opcode, so we minimize scanning and transcoding parsing.
This is our first optimization point, try to use PHP built -in functions instead of our code to achieve the same functionality.
Like our own code, PHP itself has a lot of functions built into it, so we can use multiple built-in functions to implement the same function, so is there a performance difference between built-in functions?
The answer is yes, because each function runs in different ways (like our code, implementing a function, using 10 lines of code and using 100 lines of code will have a certain time difference), the resulting opcode is not the same. This is the second point of our optimization, and we need to select the correct built-in function while using the built-in functions.
What is the PHP built-in function to choose?
PHP built-in functions have thousands of, how we choose that is the most needed for our project is indeed a more troublesome thing. It is usually necessary to familiarize yourself with commonly used functions: handling strings, handling arrays, and working with databases. (for commonly used functions, I will write the relevant topic for comparison later)
How is the test time-consuming?
1. Using the Microtime () function
function Current_time () { list($usecond,$secondexplodemicrotime ()); return (float)$usecond+ (float)$second);}
2, the use of Linux comes with the time command, the command can see the program running system times, program consumption time (user) is real time.
The display takes 12 milliseconds.
Off-topic: Test Apache and Nginx performance
Request 100 times, parallel 100 requests at a time. Apache on the left and Nginx on the right.
|
Apache |
Nginx |
Request Volume per second |
4.32 |
4415.99 |
time per request (MS) |
231.562 |
0.226 |
Language performance optimization of PHP performance