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.