Using the Ltrace tool to track the methods of PHP library function calls _php tips

Source: Internet
Author: User

The example in this article describes the method used to track PHP library function calls using the Ltrace tool. Share to everyone for your reference, specific as follows:

Maybe everyone is already familiar with using Strace to track system calls, today we introduce a tool for tracking library functions Ltrace

Like I have such a section of PHP code

test.php:

<?php
 $y = ' 1380 ';
 $arr = Array ();
 for ($i = 0; $i < $i + +) {
   $arr [] = ' {$i} ';///intentionally wrapped in quotation marks set to string
 } for
 ($i = 0; $i <; $i + +) {
   if ( !in_array ($y, $arr)) Continue
 }
? >

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

You will see the output as follows:

% time   seconds Usecs/call   calls   function
------------------------------------------------------- --
95.02  7.417240     368   20146 strtol 2.15
7.160390 413 17316 memcpy 1.63  5.522641   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   22836 malloc
 0.29   0.382083-5678

You can see that strtol almost used the execution time of 95.02%, the bottleneck was found out. and PHP tries to convert the string line number to long when the In_array () test, which can take a lot of time. So as long as the string is converted to the shaping can greatly improve efficiency.

Ltrace really is a good tool.

I hope this article will help you with the PHP program design.

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.