Home

Awesome

trace

This is a tracing API for PHP 7 processes, inspired by phpspy.

It has one default mode that prints stack traces from the target process, the target process may be any SAPI on any system that meets requirements.

It installs an API for implementors of tools or interfaces.

Requirements

🕇 : ZTS is supported if executor_globals address is known and set with -e

On ubuntu and friends, prerequisites may be installed with

sudo apt install libelf-dev libdw-dev libphp-embed php-dev

Note: If you are building PHP yourself, use --enable-embed configure option.

Building

php-trace uses the CMake build system:

git clone https://github.com/krakjoe/trace php-trace
cd php-trace
mkdir build
cd build
cmake ..
make
sudo make install

CMake will attempt to find all prerequisites and configure the build automatically, you may override the defaults:

OptionPurposeDefault
CMAKE_BUILD_TYPESet Debug/Release build typeauto
CMAKE_INSTALL_PREFIXSet installation prefixauto
PHP_CONFIGSet path to php-configauto
PHP_TRACE_LIBPHPSet path to libphp7.aauto
PHP_TRACE_LIBELFSet path to libelf.soauto
PHP_TRACE_LIBDWSet path to libdw.soauto

Executing

Executing php-trace requires root privileges:

php-trace -p PID

Options:

Option (S/L)PurposeDefault
p/processSet target process
e/executorSet executor addressauto
m/maxMaximum samples
f/frequencyFrequency (sleep)1000
d/depthMaximum stack depth64

Flags:

Flag (S/L)Purpose
s/stackCollect args/vars from stack on frame
with-array-elementsCopy array elements from stack
with-string-contentsCopy string contents from stack

Your terminal will be filled with backtraces from the target process.

SAPI Support

All PHP SAPIs are supported.

TODO