phbpf is specifically designed for PHP, enabling the efficient creation of kernel-level tracing and manipulation programs in Linux systems. Centered around eBPF technology, it offers a rich set of tools and examples to empower PHP developers with robust kernel observability and dynamic instrumentation capabilities within their familiar ecosystem.
+-------------+ +---------------------------+
| PHP Script | <----> | PHP Extension Module (C) |
+-------------+ +---------------------------+
|
v
+------------------+
| libbpf / BCC |
+------------------+
|
v
+------------------+
| eBPF Subsystem |
+------------------+
This example traces a disk I/O kernel function, and populates an in-kernel power-of-2 histogram of the I/O size. For efficiency, only the histogram summary is returned to user-level.
# php ./examples/tracing/bitehist.php
Tracing... Hit Ctrl-C to end.
^C
kbytes : count distribution
0 -> 1 : 3 | |
2 -> 3 : 0 | |
4 -> 7 : 211 |********** |
8 -> 15 : 0 | |
16 -> 31 : 0 | |
32 -> 63 : 0 | |
64 -> 127 : 1 | |
128 -> 255 : 800 |**************************************|
# Install llvm / bcc / clang, etc.
For example, on Ubuntu:
sudo apt install bpfcc-tools linux-headers-$(uname -r)
For more information on system or dependency installation issues, refer to: https://github.com/iovisor/bcc/blob/master/INSTALL.md
git clone --recursive https://git.yunzhihui.ltd/root/phbpf.git
cd phbpf
phpize
./configure
make && sudo make install
# Configure php.ini
echo "extension=ebpf.so" >> php.ini
# Run example
php examples/hello_world.php
This section is under construction. Please check back later.
Examples:
We welcome contributions to this project! Please feel free to submit a pull request.