Use the ltrace tool to trace the methods called by the PHP library functions.

Source: Internet
Author: User

Use the ltrace tool to trace the methods called by the PHP library functions.

This example describes how to use the ltrace tool to track function calls in the PHP library. We will share this with you for your reference. The details are as follows:

You may already be familiar with using strace to track system calls. Today we will introduce ltrace, a powerful tool for tracking library functions.

For example, I have such a PHP code

Test. php:

<? Php $ y = '000000'; $ arr = array (); for ($ I = 0; $ I <1380; $ I ++) {$ arr [] = "{$ I}"; // intentionally enclose the string with quotation marks} for ($ I = 0; $ I <2000; $ I ++) {if (! In_array ($ y, $ arr) continue;}?>

Ltrace-c/usr/local/php/bin/php test. php (-c Indicates summary)

The output is as follows:

% time   seconds usecs/call   calls   function------ ----------- ----------- --------- --------------------95.02  7.417240     368   20146 strtol2.15  7.160390     413   17316 memcpy1.63  5.522641     240   22966 free 0.67  2.275374   2275374     1 curl_global_cleanup 0.54  2.235466     617   3618 __ctype_tolower_loc 0.16  2.123547    1194   1778 strrchr 0.17  1.532224     67   22836 malloc 0.29  0.382083     67   5678 strlen

We can see that strtol uses almost 95.02% of the execution time, And the bottleneck is identified. And PHP will try to convert the number of the string row to long during the in_array () test, which will take a lot of time. Therefore, you only need to convert all strings into an integer, which greatly improves the efficiency.

Ltrace is a good tool.

I hope this article will help you with PHP programming.

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.