Home >Backend Development >PHP Problem >Deliverer, 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.
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
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.
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.
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
Use bin/deliverer to analyze and organize the collected logs. This is a php script, so I won’t go into details. .
$ phpize $ ./configure --with-php-config=/usr/local/php/bin/php-config $ make && sudo make install
Append
[deliverer] extension=deliverer.so
sudo service php-fpm restart
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
$ ./bin/deliverer -tAction::initUser -n3 -l5
Value | Explanation | |
---|---|---|
Action::initUser | Filter requests containing this call | |
3 | Count three times and exit | |
5 | The function (method) calls the depth display, and up to 5 layers are displayed. The excess parts are marked at the end |
$ ./bin/deliverer -tSqlExecute::getAll -n1 -l3When 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
Recommended learning:
php video tutorialThe 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!