search
HomeBackend DevelopmentPHP ProblemDeliverer, the PHP code savior you have been waiting for for so long, is here!

When a piece of code cannot see the complete call chain, do you need a tool to assist in clearly querying the entire complete call chain? This time the editor will take you to learn about Deliverer in php, so you no longer have to worry about code troubleshooting.

Deliverer, the PHP code savior you have been waiting for for so long, is here!

A few days ago, a group friend took over a piece of ancestral code. After troubleshooting for a long time, it was not solved. He prepared to run away with the bucket and finally helped him solve it. The complete process can be found at https:/ /mengkang.net/1470.html However, the positioning of the final code is based on my personal experience. The actual link called is different from what I expected, and it is all based on guesswork. I didn't see the complete call chain, so I thought I needed a tool to assist in explicitly querying the entire call chain.

So I built this tool, mainly for unfamiliar projects and online scenarios that are difficult to reproduce in daily environments.

deliver The ancestral code escape rescuer https://github.com/zhoumengka...

If your project is not that bad and the daily environment is ok, then it is best to be familiar with a project The method is still xdebug. This tool is mainly used to troubleshoot online problems.
Similar tools include 360's phptrace implementation principle, which is slightly different

Function points

  • can be based on the function name, class name, Use the method name and route to filter the output

  • You can exit after querying the specified filtered content n times

  • You can play back the entire request based on the request id The complete call chain

  • The filtered content will be highlighted

  • If the call stack is deep, you can specify -l to hide the display of deep calls.

Principle

In fact, it is relatively simple. It is divided into two steps. The first step is to collect logs and the second step is to analyze the logs.

Step 1

In the PHP_MINIT stage, use zend_set_user_opcode_handler to set up the processing and analysis of three types of opcodes: ZEND_DO_UCALL, ZEND_DO_FCALL_BY_NAME, and ZEND_DO_FCALL.

Note that it will cover calls to some built-in functions and methods, and we can filter by type.

Then create a new log file in the PHP_RINIT stage and write the requested information

pid-ts sapi http_method http_url

During the request process, print the call stack information in the custom handler

Finally close the log in PHP_RSHUTDOWN Writing files

The second step

Use bin/deliverer to analyze and organize the collected logs. This is a php script, so I won’t go into details. .

Install and use

Compile

$ phpize
$ ./configure --with-php-config=/usr/local/php/bin/php-config
$ make && sudo make install

Configure php.ini

Append

[deliverer]
extension=deliverer.so

Restart php-fpm

sudo service php-fpm restart

Use analysis tools

You can move ./bin/deliverer to where you think it is Suitable directory, if you run it in the current directory

$ chmod +x deliverer

with a piece of my own ancestral code (my blog) from long ago

$ ./bin/deliverer -t

, this will always monitor the execution of all php processes

Deliverer, the PHP code savior you have been waiting for for so long, is here!

$ ./bin/deliverer -tAction::initUser -n3 -l5

Deliverer, the PHP code savior you have been waiting for for so long, is here!

Deliverer, the PHP code savior you have been waiting for for so long, is here!

##ParameterValue Explanation-tAction::initUserFilter requests containing this call-n3Count three times and exit-l 5The function (method) calls the depth display, and up to 5 layers are displayed. The excess parts are marked at the end##
$ ./bin/deliverer -v7979-1624369150991941
View the complete details through -v requestId Call stack

$ ./bin/deliverer -tSqlExecute::getAll -n1 -l3
Deliverer, the PHP code savior you have been waiting for for so long, is here!When querying a method, the function call stack is too deep and is not within the hierarchical query range, and its outer calls are displayed in red

Deliverer, the PHP code savior you have been waiting for for so long, is here!Recommended learning:

php video tutorial

The above is the detailed content of Deliverer, the PHP code savior you have been waiting for for so long, is here!. For more information, please follow other related articles on the PHP Chinese website!

Statement
This article is reproduced at:segmentfault. If there is any infringement, please contact admin@php.cn delete
ACID vs BASE Database: Differences and when to use each.ACID vs BASE Database: Differences and when to use each.Mar 26, 2025 pm 04:19 PM

The article compares ACID and BASE database models, detailing their characteristics and appropriate use cases. ACID prioritizes data integrity and consistency, suitable for financial and e-commerce applications, while BASE focuses on availability and

PHP Secure File Uploads: Preventing file-related vulnerabilities.PHP Secure File Uploads: Preventing file-related vulnerabilities.Mar 26, 2025 pm 04:18 PM

The article discusses securing PHP file uploads to prevent vulnerabilities like code injection. It focuses on file type validation, secure storage, and error handling to enhance application security.

PHP Input Validation: Best practices.PHP Input Validation: Best practices.Mar 26, 2025 pm 04:17 PM

Article discusses best practices for PHP input validation to enhance security, focusing on techniques like using built-in functions, whitelist approach, and server-side validation.

PHP API Rate Limiting: Implementation strategies.PHP API Rate Limiting: Implementation strategies.Mar 26, 2025 pm 04:16 PM

The article discusses strategies for implementing API rate limiting in PHP, including algorithms like Token Bucket and Leaky Bucket, and using libraries like symfony/rate-limiter. It also covers monitoring, dynamically adjusting rate limits, and hand

PHP Password Hashing: password_hash and password_verify.PHP Password Hashing: password_hash and password_verify.Mar 26, 2025 pm 04:15 PM

The article discusses the benefits of using password_hash and password_verify in PHP for securing passwords. The main argument is that these functions enhance password protection through automatic salt generation, strong hashing algorithms, and secur

OWASP Top 10 PHP: Describe and mitigate common vulnerabilities.OWASP Top 10 PHP: Describe and mitigate common vulnerabilities.Mar 26, 2025 pm 04:13 PM

The article discusses OWASP Top 10 vulnerabilities in PHP and mitigation strategies. Key issues include injection, broken authentication, and XSS, with recommended tools for monitoring and securing PHP applications.

PHP XSS Prevention: How to protect against XSS.PHP XSS Prevention: How to protect against XSS.Mar 26, 2025 pm 04:12 PM

The article discusses strategies to prevent XSS attacks in PHP, focusing on input sanitization, output encoding, and using security-enhancing libraries and frameworks.

PHP Interface vs Abstract Class: When to use each.PHP Interface vs Abstract Class: When to use each.Mar 26, 2025 pm 04:11 PM

The article discusses the use of interfaces and abstract classes in PHP, focusing on when to use each. Interfaces define a contract without implementation, suitable for unrelated classes and multiple inheritance. Abstract classes provide common funct

See all articles

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

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Safe Exam Browser

Safe Exam Browser

Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

Atom editor mac version download

Atom editor mac version download

The most popular open source editor

EditPlus Chinese cracked version

EditPlus Chinese cracked version

Small size, syntax highlighting, does not support code prompt function

SecLists

SecLists

SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.