Performance Optimization of PHP Exploitation Program

Source: Internet
Author: User
The biggest benefit of applying PHP programming is that it is very easy to learn this programming language and its rich libraries. Even if we are not very familiar with the functions to be applied, we can guess how to complete a specific task. Although PHP is easy to learn, we

The biggest benefit of applying PHP programming is that it is very easy to learn this programming language and its rich libraries. Even if we are not very familiar with the functions to be applied, we can guess how to complete a specific task.

Although PHP is easy to learn, it still takes a little time to learn some PHP programming skills, especially those related to performance and memory usage. In PHP, there are many tips that can help us reduce memory usage and improve the performance of the exploitation program. In this article, we will briefly introduce the analysis of PHP Exploitation programs, how to change the script code, and compare various parameter values before and after optimization.

By setting the timing program in the program and repeating the code, we can obtain a set of data about the program's performance speed, which can be used to invent bottlenecks in the program, and how to optimize and improve the performance of the exploitation program.

Maybe you have heard of the PEAR Library. We will use the PEAR library as an example for analysis. this is also the simplest method for analyzing existing code, it allows us to analyze code without having to use commercial products.

The library we want to apply is named PEAR: Benchmark, which is very useful for code analysis and performance testing. This library provides a class named Benchmark_Timer (), which records the time between a function call and the next function call. When testing the code performance, we can get a specific script fulfillment result, which is very simple, as shown below:

Include_once ('benchmark/Timer. php ');
$ Timer = new Benchmark_Timer;

$ Begin-> start ();
$ Marker-> setMarker ('Start of the script ');

// Sleep for several minutes
Sleep (5 );

$ Response-> stop ();

// Obtain the analysis information from the timer
Print_r ($ response-> getProfiling ());
?>


The output after the above code is executed is as follows:


Array
(
[0] => Array
(
[Name] => Start
[Time] = & gt; 1013214253.05751200
[Diff] =>-
[Total] => 0
)

[1] => Array
(
[Name] => Start of the script
[Time] = & gt; 1013214253.05761100
[Diff] => 9.8943710327148E-05
[Total] => 9.8943710327148E-05
)

[2] => Array
(
[Name] => Stop
[Time] = & gt; 1013214258.04920700
[Diff] = & gt; 4.9915959835052
[Total] = & gt; 4.9916949272156
)

)

 

 

The numbers above seem to be a group of chaotic numbers, but they are very useful if the program is wider.

Maybe the wide reader can guess that the first table in the array is actually calling the Benchmark_Timer () class method, for example

$ Marker-> start (), $ marker-> setMarker (), and $ marker-> stop (). the numbers related to these tables are quite simple, now let's take a closer look at these numbers:

[0] => Array

(

[Name] => Start

[Time] = & gt; 1013214253.05751200

[Diff] =>-

[Total] => 0

)

The time table refers to the UNIX timestamp when the start () method of Benchmark_Timer () is called. the diff table shows the time interval between this call and the last call, because there is no previous one, a broken number is displayed. The total table refers to the total time of code running from the beginning of the test to the specific call. Next let's take a look at the output of the next array:

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.