Language performance optimization of PHP performance

Source: Internet
Author: User
Tags php language

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

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.