Home Backend Development PHP Tutorial 使用ltrace工具跟踪PHP库函数调用的方法_PHP

使用ltrace工具跟踪PHP库函数调用的方法_PHP

May 29, 2016 am 11:46 AM
track

本文实例讲述了使用ltrace工具跟踪PHP库函数调用的方法。分享给大家供大家参考,具体如下:

可能大家已经很熟悉使用strace来跟踪系统调用,今天介绍一个跟踪库函数的利器ltrace

比如我有这么一段PHP代码

test.php:

<&#63;php
 $y = '1380';
 $arr = array();
 for($i = 0; $i < 2000; $i ++){
   $arr[] = "{$i}"; //故意用引号包起来设成字符串
 }
 for($i = 0; $i < 2000; $i ++){
   if(!in_array($y, $arr)) continue;
 }
&#63;>

Copy after login

ltrace -c /usr/local/php/bin/php test.php (-c表示汇总)

会看到输出如下:

% time   seconds usecs/call   calls   function
------ ----------- ----------- --------- --------------------
95.02  7.417240     368   20146 strtol
2.15  7.160390     413   17316 memcpy
1.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

Copy after login

可以看到 strtol几乎用去了执行时间的95.02%,瓶颈就找出来了。及PHP会在in_array()测试时试图将字符串行数字转换为long,这会耗费大量时间。所以只要将字符串都转换为整形即可大幅度提高效率。

ltrace真心是个好工具

希望本文所述对大家PHP程序设计有所帮助。

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Path tracing and ray tracing for game visual effects Path tracing and ray tracing for game visual effects Feb 19, 2024 am 11:36 AM

The decision to use path tracing or ray tracing is a critical choice for game developers. Although they both perform well visually, there are some differences in practical applications. Therefore, game enthusiasts need to carefully weigh the advantages and disadvantages of both to determine which technology is more suitable for achieving the visual effects they want. What is ray tracing? Ray tracing is a complex rendering technique used to simulate the propagation and interaction of light in virtual environments. Unlike traditional rasterization methods, ray tracing generates realistic lighting and shadow effects by tracing the path of light, providing a more realistic visual experience. This technology not only produces more realistic images, but also simulates more complex lighting effects, making scenes look more realistic and vivid. its main concepts

How to use logging to track program execution in C# How to use logging to track program execution in C# Oct 09, 2023 pm 03:51 PM

How to use logging to track program operation in C# requires specific code examples. Introduction: When developing software, it is often necessary to track and record the operation of the program so that the problem can be accurately found when a problem occurs. Logging is an important technical means that can record the running status, error information and debugging information of the program to facilitate abnormal location and troubleshooting. This article will introduce how to use logging to track the operation of the program in C#, and provide specific code examples. 1. Selection of logging libraries In C#, there are many excellent ones

Implementation method of order status tracking function of food shopping system developed in PHP Implementation method of order status tracking function of food shopping system developed in PHP Nov 02, 2023 pm 02:28 PM

Implementation method of order status tracking function of vegetable shopping system developed in PHP With the rapid development of e-commerce, more and more people begin to purchase daily necessities online, including daily ingredients and vegetables. In order to facilitate users to purchase vegetables, many vegetable shopping systems have begun to emerge, providing users with online purchase, payment and delivery services. In the grocery shopping system, the order status tracking function is particularly important, allowing users to understand the status of their orders in real time, thereby improving the user's shopping experience. This article will introduce the implementation of the order status tracking function of the grocery shopping system developed in PHP.

PHP debugging tips: How to use the debug_backtrace function to trace the code execution path PHP debugging tips: How to use the debug_backtrace function to trace the code execution path Jul 29, 2023 am 10:24 AM

PHP debugging tips: How to use the debug_backtrace function to trace the code execution path Introduction: During the development process, you often encounter situations where you need to trace the code execution path in order to find out where the error is. PHP provides a very useful function debug_backtrace, which can be used to obtain stack information of function calls, thereby helping us track down errors. This article will introduce the usage of debug_backtrace function and provide some usage examples. 1. debug_back

Error tracking and logging using PHP error handling classes Error tracking and logging using PHP error handling classes Aug 08, 2023 pm 02:22 PM

Using PHP error handling classes for error tracking and recording error handling is a very important part of the development process and can help us track and solve bugs in the program. In PHP, we can use built-in error handling functions and custom error handling classes to handle errors that occur during program running. This article will introduce how to use PHP error handling classes for error tracking and logging. We first need to create a custom error handling class. Error handling classes can inherit from PHP's built-in errors

Implementation Guide for UniApp to Implement Takeaway Ordering and Delivery Tracking Implementation Guide for UniApp to Implement Takeaway Ordering and Delivery Tracking Jul 04, 2023 am 09:03 AM

Introduction to UniApp’s Guide to Implementing Takeout Ordering and Delivery Tracking: With the rapid development of the takeout market, more and more people choose to order takeout and deliver it through mobile APPs, which brings more business opportunities and challenges to the catering industry. . As a cross-platform development framework, UniApp can develop multi-platform applications quickly and efficiently. This article will introduce how to use UniApp to implement takeout ordering and delivery tracking functions, and attach relevant code examples. 1. Requirements analysis User login: Users need to pass their mobile phone number or

How to use PHP and Xunsearch for search result tracking and log analysis How to use PHP and Xunsearch for search result tracking and log analysis Aug 05, 2023 pm 07:45 PM

How to use PHP and Xunsearch for search result tracking and log analysis. With the rapid development of the Internet, search engines have become an indispensable part of our daily lives. Whether it is shopping, academic research or entertainment consulting, search engines can help us get the information we need. For search engine developers, it is very important to understand users' search behavior and analyze the quality of search results. This article will introduce how to use PHP and Xunsearch for search result tracking and log analysis. first,

Methods and techniques for debugging and solving Linux network security issues Methods and techniques for debugging and solving Linux network security issues Jun 30, 2023 pm 11:13 PM

How to debug and solve network security problems in Linux systems. With the rapid development of the Internet, network security has become an increasingly important topic. As one of the most popular operating systems, Linux systems have certain advantages in network security. However, even Linux systems are not completely immune to cyberattacks. Therefore, it is crucial to know how to debug and resolve network security issues in Linux systems. This article will cover some common network security issues and provide some suggestions and tips for debugging and resolving them.

See all articles