Nincs leírás

Carl db6130b9c0 Initial commit (README) 8 hónapja
api db6130b9c0 Initial commit (README) 8 hónapja
deps 3d49bc05ca Initial commit 8 hónapja
examples 2afbb1cf84 Initial commit (add demo) 8 hónapja
tests 3d49bc05ca Initial commit 8 hónapja
.gitignore 3d49bc05ca Initial commit 8 hónapja
.gitmodules 3d49bc05ca Initial commit 8 hónapja
CREDITS 3d49bc05ca Initial commit 8 hónapja
EXPERIMENTAL 3d49bc05ca Initial commit 8 hónapja
README.md db6130b9c0 Initial commit (README) 8 hónapja
config.m4 db6130b9c0 Initial commit (README) 8 hónapja
config.w32 3d49bc05ca Initial commit 8 hónapja
ebpf.cpp db6130b9c0 Initial commit (README) 8 hónapja
ebpf.php 3d49bc05ca Initial commit 8 hónapja
php_ebpf.h db6130b9c0 Initial commit (README) 8 hónapja

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.

# ./examples/bitehist.py
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      |**************************************|

🔗 依赖

  • PHP 7+
  • 内核,开启 BPF 支持
  • libbpf
  • BCC
  • Clang / LLVM

🚀 快速开始

依赖安装

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

更多系统参考: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