Extension implementation PHP Benchmark

Source: Internet
Author: User
ArticleDirectory
    • I. php benchmark Implementation ideas
    • 2. Help analysis and viewing of webpage client scripts
    • Iii. Installation Process
I. php benchmark Implementation ideas

In the process of viewing redis slow query log implementation, I think this function is very useful and can help to quickly analyze the source of performance problems, so I want to implement this function for PHP.

The implementation method also draws on redis's processing process for slow queries.(Currently, this extension only supports Linux)

This extension is used to help analyze the elements of PHP script records that have been executed for too long:

1. script execution time

2. Request data of the current request

3. Relative file path of the current request

4. Cookie data of the current request

The data transmitted by record is used to simulate performance problems that occur only when special data is used.

The storage medium selects memcache instead of files, because it does not want the bottleneck caused by disk writing and data can be lost.

If you want persistence, you can use the client to regularly store logs without the need for real-time persistent storage.

Implementation ideas:

1. Set the maximum script timeout slowlog. slow_maxtime (unit: 1 S = 000000us)

2. In the rinit stage of the script, the current time is recorded as start. When the current time of the rshotdown stage is recorded as end, the time difference is the duration execution time.

Here, the rinit and rshutdown phases are understood as follows:

3. When the execution time duration is greater than the slowlog. slow_maxtime set, perform step 4.

4. Obtain the log auto-increment id with the memcache key slowlog_idx, and store the current four-point record elements (the four elements listed at the beginning) under slowlog _ (auto-increment ID, at the same time, the updated slowlog_idx key value is auto-incremental ID ++.

In this case, a script that exceeds the specified execution time is recorded in memcache.

2. Help analysis and viewing of webpage client scripts

After the logs are retrieved from memcache, the data is computed and the average statistics in file units are displayed in a pie chart. Click the pie chart to display the detailed log information of this file.

Iii. Installation Process

1. Download extended source http://yunpan.cn/Q5AaJjs4kP63x

2,

 

# If you have not installed memcache, you need to first install memcache extension and memcache servertar-xvf slowlog.tar CD slowlog/usr/local/PHP/bin/phpize # here you need to set your PHP installation directory. /configure -- With-PHP-Config =/usr/local/PHP/bin/PHP-config # Set make & make install to your PHP installation directory.

 

3. Added in PHP. ini

 

 
Extension = slowlog. So [slowlog] slowlog. slow_maxtime = 1000000 # indicates that the timeout is 1sslowlog. mem_host = locahostslowlog. mem_port = 11211

Now the extended installation configuration is complete.

 

4. Use the client (View on the webpage)

The client file is in the client folder under the source package. Copy the client to the site and access http: // localhost/client/slowlog. php to view the slow execution log.

NOTE: If your memcache server address is not localhost or port 11211, modify the connection information.

 

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.