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.