Improve php program performance and load testing

Source: Internet
Author: User
Tags php debugger
An example code about improving php program performance and load testing. if you need it, you can see how to improve the performance of your program. calculate the execution time. the following simple method can be used to calculate the execution time of a program (subtle). The code is as follows: $ start_ti... an example code about improving php program performance and load testing. if you need it, you can see how to improve the performance of your program.

Calculate the execution time. the following simple method can be used to calculate the execution time of a program (subtle). The code is as follows:

$ Start_time = microtime (true); // code that requires time to be calculated //... code here... print ('code running time is :'. getExecTime ($ start_time); function getExecTime ($ start_time) {return microtime (true)-$ start_time ;} PEAR's Benchmark module provides more detailed time statistics functions: require_once 'Benchmark/Timer. php '; $ timer = & new Benchmark_Timer (true); $ timer-> start (); // Set the function $ timer-> setMarker ('setup '); // some more code executed here $ timer-> setMarker ('middle'); // even yet still more code here $ timer-> setmarker ('done '); // and a last bit of code here $ timer-> stop (); $ timer-> display (); the declare structure and ticks command can be used to automatically record the execution time of each PHP code line. // A function that records the time when it is called function profile ($ dump = FALSE) {static $ profile; // Return the times stored in profile, then erase it if ($ dump) {$ temp = $ profile; unset ($ profile ); return ($ temp) ;}$ profile [] = microtime () ;}// Set up a tick handler register_tick_function ("profile "); // Initialize the function before the declare block profile (); // Run a block of code, throw a tick every 2nd statement declare (ticks = 2) {for ($ x = 1; $ x <50; ++ $ x) {echo similar_text (md5 ($ x), md5 ($ x * $ x )),"; ";}}

// Display the data stored in the profiler

Print_r (profile (TRUE); Note: the ticks command is outdated in PHP 5.3.0 and will be removed from PHP 6.0.0.

Code troubleshooting

This section describes Advanced PHP Debugger (APD). you can generate a trace file by setting the file, and analyze the file to obtain detailed information about the script.

Website stress testing

People often confuse stress testing and benchmarking. benchmarking is a temporary activity completed by individual developers. Apache HTTP testing tools are commonly used-AB, this tool can test the number of requests per second on an HTTP server. Stress testing is a testing technology that can interrupt your WEB application. through Breakpoint testing, identifies and fixes vulnerabilities in applications and provides a basis for purchasing new hardware. the commonly used open-source tool is Siege.

Acceleration skills

Installing the PHP Accelerator can effectively provide PHP execution speed. The three common accelerators are Alternative PHP Cache (APC), eAccelerator, and ionCube PHP Accelerator (PHPA ), note that the accelerator compatibility usually lags behind the newly released PHP version.

In addition, the speed-up technique is to avoid using regular expressions whenever possible. Generally, the alternative solution is more efficient than using regular expressions.


Article link:

Save this article for favorites!

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.