Tidak Ada Deskripsi

Carl ec9a62a3b0 Initial commit (php8) 10 bulan lalu
api db6130b9c0 Initial commit (README) 10 bulan lalu
deps 3d49bc05ca Initial commit 10 bulan lalu
examples 2afbb1cf84 Initial commit (add demo) 10 bulan lalu
tests 3d49bc05ca Initial commit 10 bulan lalu
.gitignore 3d49bc05ca Initial commit 10 bulan lalu
.gitmodules 3d49bc05ca Initial commit 10 bulan lalu
CREDITS 3d49bc05ca Initial commit 10 bulan lalu
EXPERIMENTAL 3d49bc05ca Initial commit 10 bulan lalu
README.md ec9a62a3b0 Initial commit (php8) 10 bulan lalu
config.m4 ec9a62a3b0 Initial commit (php8) 10 bulan lalu
config.w32 3d49bc05ca Initial commit 10 bulan lalu
ebpf.cpp ec9a62a3b0 Initial commit (php8) 10 bulan lalu
ebpf.php 3d49bc05ca Initial commit 10 bulan lalu
php_ebpf.h db6130b9c0 Initial commit (README) 10 bulan lalu
wrapper.h ec9a62a3b0 Initial commit (php8) 10 bulan lalu

README.md

eBPF Observability for PHP

phbpf 是专为 PHP 打造的,用于在 Linux 系统中高效创建内核级跟踪与操作程序。以 eBPF 技术为核心,提供丰富的工具与示例,帮助 PHP 开发者在熟悉的生态下,使用强大的内核观测与动态插桩能力。

✨ 特性

  • 原生 PHP 脚本直接操作 BPF 程序,适合快速开发与调试eBPF功能
  • 遵循 bcc 前端使用习惯,以极低成本将 bcc 工具项目使用php实现,内置使用样例
  • 核心逻辑使用 C/C++ 编写,调用 libbpf 和 LLVM 接口
  • 支持常用BPF hook:kprobe/uprobe、tracepoint 等
  • 外部独立进程,无感知监控正在运行的系统及目标进程

🛠 架构概览

+-------------+        +---------------------------+
|  PHP Script  | <----> | PHP Extension Module (C) |
+-------------+        +---------------------------+
                                   |
                                   v
                          +------------------+
                          |   libbpf / BCC   |
                          +------------------+
                                   |
                                   v
                          +------------------+
                          |  eBPF Subsystem  |
                          +------------------+

Screenshot

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      |**************************************|

🔗 依赖

🚀 快速开始

依赖安装

# 安装llvm / bcc / clang 等
例如 Ubuntu:
sudo apt install bpfcc-tools linux-headers-$(uname -r)

更多系统参考: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
# 配置 php.ini
echo "extension=ebpf.so" >> php.ini
# 运行示例
php examples/hello_world.php

Contents