Skip to content

Hook cheat sheet: PHP ​

How to add a vulnboxd runtime hook to a PHP service by hand. Find your setup in the table, then follow its block.

  • Without source access: only the compose file changes; redeploy. With source access: you change the code or Dockerfile and rebuild.
  • Hub automation says how much the hub's proposals do for you. Fully: approve the proposal in the hub; the block is the fallback when it failed. With conditions: the same, when the conditions listed hold. Partly: the hub pushes the compose part, the rest is yours. Not at all: everything is by hand.
  • /usr/local/lib/vulnboxd/trace is the hook directory vulnboxd installs on the vulnbox. Compose snippets mount it read-only at /opt/vbxtrace in the container.
  • How to check that the hook works and undo it is at the end of the page.
  • Runtime hooks explains what a hook does.

PHP ​

SetupUse this whenChangeHub automation
PHP request hook (vbxtrace extension)Started with php-fpm, apache2-foreground, php or frankenphpcompose + mounted configwith conditions
PHP request hook (FFI, preloaded)Depends on ext-ffi (in composer.json), and only if PHP has the FFI extension (ext-ffi) and OPcache is enabledcompose + mounted configwith conditions
PHP request hook (CLI runtimes with FFI)Depends on swoole/ide-helper, workerman/workerman, react/http, amphp/http-server or spiral/roadrunner-http (in composer.json), and only if PHP has the FFI extension (ext-ffi)compose + mounted configwith conditions
PHP request hook (FFI enabled for all code)Started with php-cgi or php, and only if PHP has the FFI extension (ext-ffi)compose + mounted configwith conditions
Amp: request context per fiberDepends on amphp/http-server (in composer.json); a companion to H1:ext or H1:basic or H1:preload or H1:ffisource, rebuildnot at all
FrankenPHP worker mode: request boundariesDepends on runtime/frankenphp-symfony or laravel/octane (in composer.json); a companion to H1:ext or H1:basic or H1:preload or H1:ffisource, rebuildnot at all
ReactPHP: request boundaries for the HTTP serverDepends on react/http (in composer.json); a companion to H1:ext or H1:basic or H1:preload or H1:ffisource, rebuildnot at all
RoadRunner: request boundaries in the PHP workerDepends on spiral/roadrunner-http, spiral/roadrunner or spiral/framework (in composer.json); a companion to H1:ext or H1:basic or H1:preload or H1:ffisource, rebuildnot at all
Swoole / OpenSwoole: request context per coroutineDepends on swoole/ide-helper, openswoole/ide-helper, hyperf/framework or laravel/octane (in composer.json); a companion to H1:ext or H1:basic or H1:preload or H1:ffisource, rebuildnot at all
Workerman: request boundaries per messageDepends on workerman/workerman or workerman/webman-framework (in composer.json); a companion to H1:ext or H1:basic or H1:preload or H1:ffisource, rebuildnot at all
Add PHP's FFI extension to the imageOn the image phpsource, rebuildnot at all
nginx: pass the request index and local port to PHP-FPMOn the image nginx, trafex/php-nginx or webdevops/php-nginx; a companion to H1:ext or H1:preload or H1:ffisource, rebuildnot at all

Without source access ​

Only the compose file changes: the image and the code stay as they are.

PHP request hook (vbxtrace extension) ​

  • Use this when: PHP service started with php-fpm, apache2-foreground, php or frankenphp.
  • Hub automation: with conditions. The hub proposes and pushes exactly this change. Only when it can work out <php_ext> (php_ext_triple); otherwise do it by hand.
  • Check and undo: hook mounted into the container

Mounts an ini file that loads vulnboxd's prebuilt vbxtrace extension and runs the request hook before every script. For PHP without ext-ffi: every official php image, phpswoole/swoole, openswoole/swoole, dunglas/frankenphp. Image and source untouched.

Compose: merge into the service (app is its name) and redeploy:

yaml
services:
  app:
    volumes:
      - /usr/local/lib/vulnboxd/trace:/opt/vbxtrace:ro
      - /usr/local/lib/vulnboxd/trace/php/conf.d/zz-vbxtrace-ext.ini:/usr/local/etc/php/conf.d/zz-vbxtrace.ini:ro
      - /usr/local/lib/vulnboxd/trace/php/ext/vbxtrace-<php_ext>.ini:/usr/local/etc/php/conf.d/zz-vbxtrace-ext.ini:ro

Values: chain_prepend (php_ini:auto_prepend_file) is left out when there is none; /usr/local/etc/php/conf.d is the usual php_conf_d (php_conf_d); <php_ext> is php_ext_triple. The package page says how to find each.

The mounted file, as the hook directory has it (hooks/php/h1/php/conf.d/zz-vbxtrace-ext.ini):

ini
; vbxtrace (docs/hooks/h1.md, h2.md), extension variant: mount as conf.d/zz-vbxtrace.ini.
;
; For PHP without ext-ffi (every official php image, phpswoole/swoole, openswoole/swoole,
; dunglas/frankenphp): the prebuilt vbxtrace extension, which must match the PHP minor version, NTS/ZTS and
; the architecture, is loaded by a second file the hub mounts next to this one:
; /opt/vbxtrace/php/ext/vbxtrace-<triple>.ini as conf.d/zz-vbxtrace-ext.ini, e.g. for the triple
; "php8.3-nts-x86_64" (php -v shows the version and NTS/ZTS). The triple is fixed in that file name, not
; taken from the environment, so a php process started through sudo or env -i loads the same extension and
; never prints a startup warning into a service's output. Works in every SAPI; user code gets no FFI rights.

; The request hook: runs /opt/vbxtrace/php/prepend.php before every script. Replaces any auto_prepend_file
; set earlier; the service's own one is chained when VBXTRACE_CHAIN_PREPEND names it.
auto_prepend_file = /opt/vbxtrace/php/prepend.php
vbxtrace.chain_prepend_file = "${VBXTRACE_CHAIN_PREPEND}"

; Copies of the switches taken at startup, so they survive php-fpm's clear_env.
vbxtrace.env = "${VBXTRACE}"
vbxtrace.chaos = "${VBXTRACE_CHAOS}"
Exact detection rules

Package H1 (PHP process models (kernel)), proposal H1:ext, defined in hooks/php/h1/proposals/ext.toml.

  • Image matches (regex): ^(docker\.io/)?(library/)?php:, ^phpswoole/swoole, ^openswoole/swoole, ^dunglas/frankenphp, ^bitnami/php-fpm, ^webdevops/php, ^trafex/php-nginx
  • Command matches (regex): \bphp-fpm, \bapache2-foreground\b, \bphp\b, \bfrankenphp\b
  • Files: composer.json, *.php, public/index.php

PHP request hook (FFI, preloaded) ​

  • Use this when: PHP service that depends on ext-ffi (in composer.json), and only if PHP has the FFI extension (ext-ffi) and OPcache is enabled.
  • Hub automation: with conditions. The hub proposes and pushes exactly this change. Only when it can tell that PHP has the FFI extension (ext-ffi), it can tell that OPcache is enabled, it can work out <php_user> (php_worker_user), <php_user> is www-data; otherwise do it by hand.
  • Check and undo: hook mounted into the container

Mounts an ini file that preloads the request hook with OPcache, so the hook (and only the hook) may use FFI under the default ffi.enable=preload. For images that already have ext-ffi (Debian/Alpine PHP packages, images that installed it) with OPcache on: PHP-FPM, Apache mod_php, FrankenPHP.

Compose: merge into the service (app is its name) and redeploy:

yaml
services:
  app:
    volumes:
      - /usr/local/lib/vulnboxd/trace:/opt/vbxtrace:ro
      - /usr/local/lib/vulnboxd/trace/php/conf.d/zz-vbxtrace-preload.ini:/usr/local/etc/php/conf.d/zz-vbxtrace.ini:ro

Values: chain_preload (php_ini:opcache.preload) is left out when there is none; chain_prepend (php_ini:auto_prepend_file) is left out when there is none; /usr/local/etc/php/conf.d is the usual php_conf_d (php_conf_d); <php_user> is php_worker_user. The package page says how to find each.

The mounted file, as the hook directory has it (hooks/php/h1/php/conf.d/zz-vbxtrace-preload.ini):

ini
; vbxtrace (docs/hooks/h1.md), preload variant: mount as conf.d/zz-vbxtrace.ini.
;
; For FPM, Apache mod_php, php -S and FrankenPHP with OPcache enabled. Preloads the binding so that it, and
; only it, may use FFI under the default ffi.enable=preload: user code gets no FFI rights.
;
; Needs: OPcache loaded and enabled (official php images 8.1+ enable it), ext-ffi or the vbxtrace extension,
; and the /opt/vbxtrace mount: a missing preload script stops PHP from starting. opcache.preload_user must
; name an existing user when PHP starts as root (www-data in the official images).

; The request hook: runs /opt/vbxtrace/php/prepend.php before every script. Replaces any auto_prepend_file
; set earlier; the service's own one is chained when VBXTRACE_CHAIN_PREPEND names it.
auto_prepend_file = /opt/vbxtrace/php/prepend.php
vbxtrace.chain_prepend_file = "${VBXTRACE_CHAIN_PREPEND}"

; Copies of the switches taken at startup, so they survive php-fpm's clear_env.
vbxtrace.env = "${VBXTRACE}"
vbxtrace.chaos = "${VBXTRACE_CHAOS}"

; Preloading. Replaces any opcache.preload set earlier; the service's own script is chained when
; VBXTRACE_CHAIN_PRELOAD names it.
opcache.preload = /opt/vbxtrace/php/preload.php
opcache.preload_user = www-data
vbxtrace.chain_preload = "${VBXTRACE_CHAIN_PRELOAD}"
Exact detection rules

Package H1 (PHP process models (kernel)), proposal H1:preload, defined in hooks/php/h1/proposals/preload.toml.

  • Image matches (regex): ^(docker\.io/)?(library/)?php:.*(fpm|apache), ^debian, ^ubuntu, ^alpine
  • Command matches (regex): \bphp-fpm, \bapache2, \bfrankenphp\b
  • Dependency on: ext-ffi
  • Files: composer.json, *.php
  • Required fact: php_has_ffi
  • Required fact: php_opcache_enabled

PHP request hook (CLI runtimes with FFI) ​

  • Use this when: PHP service that depends on swoole/ide-helper, workerman/workerman, react/http, amphp/http-server or spiral/roadrunner-http (in composer.json), and only if PHP has the FFI extension (ext-ffi).
  • Hub automation: with conditions. The hub proposes and pushes exactly this change. Only when it can tell that PHP has the FFI extension (ext-ffi); otherwise do it by hand.
  • Check and undo: hook mounted into the container

Mounts the basic ini file: loads the hook in long-running CLI servers (Swoole, Workerman, ReactPHP, Amp, RoadRunner workers), where PHP allows FFI by default. Needs ext-ffi; the H2 source change then wraps the server's handler.

Compose: merge into the service (app is its name) and redeploy:

yaml
services:
  app:
    volumes:
      - /usr/local/lib/vulnboxd/trace:/opt/vbxtrace:ro
      - /usr/local/lib/vulnboxd/trace/php/conf.d/zz-vbxtrace.ini:/usr/local/etc/php/conf.d/zz-vbxtrace.ini:ro

Values: chain_prepend (php_ini:auto_prepend_file) is left out when there is none; /usr/local/etc/php/conf.d is the usual php_conf_d (php_conf_d). The package page says how to find each.

The mounted file, as the hook directory has it (hooks/php/h1/php/conf.d/zz-vbxtrace.ini):

ini
; vbxtrace (docs/hooks/h1.md, h2.md), basic variant: mount as conf.d/zz-vbxtrace.ini.
;
; Enough wherever PHP lets the hook use FFI or the vbxtrace extension at run time: the CLI SAPI (Swoole,
; OpenSwoole, Workerman, ReactPHP, Amp, RoadRunner workers) with the default ffi.enable=preload, or any SAPI
; when ffi.enable=1 is already set or the vbxtrace extension is loaded. Elsewhere (FPM, Apache, php -S,
; FrankenPHP without FFI rights) it stays off: use zz-vbxtrace-preload.ini or zz-vbxtrace-ffi.ini there.

; The request hook: runs /opt/vbxtrace/php/prepend.php before every script. Replaces any auto_prepend_file
; set earlier; the service's own one is chained when VBXTRACE_CHAIN_PREPEND names it.
auto_prepend_file = /opt/vbxtrace/php/prepend.php
vbxtrace.chain_prepend_file = "${VBXTRACE_CHAIN_PREPEND}"

; Copies of the switches taken at startup, so they survive php-fpm's clear_env.
vbxtrace.env = "${VBXTRACE}"
vbxtrace.chaos = "${VBXTRACE_CHAOS}"
Exact detection rules

Package H1 (PHP process models (kernel)), proposal H1:basic, defined in hooks/php/h1/proposals/basic.toml.

  • Command matches (regex): \bphp\b.*\.php
  • Dependency on: swoole/ide-helper, workerman/workerman, react/http, amphp/http-server, spiral/roadrunner-http
  • Files: composer.json
  • Required fact: php_has_ffi

PHP request hook (FFI enabled for all code) ​

  • Use this when: PHP service started with php-cgi or php, and only if PHP has the FFI extension (ext-ffi).
  • Hub automation: with conditions. The hub proposes and pushes exactly this change. Only when it can tell that PHP has the FFI extension (ext-ffi); otherwise do it by hand.
  • Check and undo: hook mounted into the container

Mounts an ini file with ffi.enable=1 and the request hook. Last resort when ext-ffi is present but neither the extension nor preloading fits (CGI, no OPcache). Warning shown with the proposal: ffi.enable=1 lets any code in the service, including an attacker's, use FFI and bypass disable_functions/open_basedir.

WARNING

Enables PHP FFI for all code in the service.

Compose: merge into the service (app is its name) and redeploy:

yaml
services:
  app:
    volumes:
      - /usr/local/lib/vulnboxd/trace:/opt/vbxtrace:ro
      - /usr/local/lib/vulnboxd/trace/php/conf.d/zz-vbxtrace-ffi.ini:/usr/local/etc/php/conf.d/zz-vbxtrace.ini:ro

Values: chain_prepend (php_ini:auto_prepend_file) is left out when there is none; /usr/local/etc/php/conf.d is the usual php_conf_d (php_conf_d). The package page says how to find each.

The mounted file, as the hook directory has it (hooks/php/h1/php/conf.d/zz-vbxtrace-ffi.ini):

ini
; vbxtrace (docs/hooks/h1.md, h2.md), FFI variant: mount as conf.d/zz-vbxtrace.ini.
;
; For any SAPI with ext-ffi when OPcache preloading is not an option (no OPcache, CGI, PHP 7.4).
; Trade-off: ffi.enable=1 gives FFI to ALL code in the service, including code an attacker manages to run,
; which then bypasses disable_functions and open_basedir. Prefer the preload variant or the extension.

; The request hook: runs /opt/vbxtrace/php/prepend.php before every script. Replaces any auto_prepend_file
; set earlier; the service's own one is chained when VBXTRACE_CHAIN_PREPEND names it.
auto_prepend_file = /opt/vbxtrace/php/prepend.php
vbxtrace.chain_prepend_file = "${VBXTRACE_CHAIN_PREPEND}"

; Copies of the switches taken at startup, so they survive php-fpm's clear_env.
vbxtrace.env = "${VBXTRACE}"
vbxtrace.chaos = "${VBXTRACE_CHAOS}"

ffi.enable = 1
Exact detection rules

Package H1 (PHP process models (kernel)), proposal H1:ffi, defined in hooks/php/h1/proposals/ffi.toml.

  • Command matches (regex): \bphp-cgi, \bphp\b
  • Files: composer.json, *.php
  • Required fact: php_has_ffi

With source access ​

These change the service's code or Dockerfile, then it is rebuilt.

Amp: request context per fiber ​

  • Use this when: PHP service that depends on amphp/http-server (in composer.json); a companion to H1:ext or H1:basic or H1:preload or H1:ffi.
  • Hub automation: not at all. The hub lists these steps with its proposal but changes nothing.
  • Check and undo: hook built into the service

Wraps the RequestHandler given to SocketHttpServer::start(): a decorator that starts each request's context in its fiber and ends it with the response status.

Source change, then rebuild:

  1. Wrap the request handler before $server->start($handler, $errorHandler): $handler = \VbxTrace\Hook::wrap('amp', $handler).
  2. Keep the class_exists() guard: the service must run unchanged when the hook is reverted.

Example change on a sample service (hooks/php/h2/proposals/amp.diff):

diff
--- a/server.php
+++ b/server.php
@@ -45,6 +45,11 @@
 });
 
+// vbxtrace (docs/hooks/h2.md): request context per fiber. A no-op without the hook.
+if (class_exists(\VbxTrace\Hook::class, false)) {
+    $handler = \VbxTrace\Hook::wrap('amp', $handler);
+}
+
 $server = SocketHttpServer::createForDirectAccess(new NullLogger());
 $server->expose('127.0.0.1:8080');
 $server->start($handler, new DefaultErrorHandler());
Exact detection rules

Package H2 (Long-running PHP), proposal H2:amp, defined in hooks/php/h2/proposals/amp.toml.

  • Dependency on: amphp/http-server
  • Where the change goes (regex): ->start\(\s*\$

FrankenPHP worker mode: request boundaries ​

  • Use this when: PHP service that depends on runtime/frankenphp-symfony or laravel/octane (in composer.json); a companion to H1:ext or H1:basic or H1:preload or H1:ffi.
  • Hub automation: not at all. The hub lists these steps with its proposal but changes nothing.
  • Check and undo: hook built into the service

Wraps the callback given to frankenphp_handle_request() in the worker script. (FrankenPHP's classic mode needs no source change: H1's config proposal covers it.)

Source change, then rebuild:

  1. Wrap the callback: frankenphp_handle_request(\VbxTrace\Hook::wrap('frankenphp', $handler)).
  2. Keep the class_exists() guard: the service must run unchanged when the hook is reverted.

Example change on a sample service (hooks/php/h2/proposals/frankenphp.diff):

diff
--- a/public/worker.php
+++ b/public/worker.php
@@ -38,6 +38,11 @@
 };
 
+// vbxtrace (docs/hooks/h2.md): request boundaries in worker mode. A no-op without the hook.
+if (class_exists(\VbxTrace\Hook::class, false)) {
+    $handler = \VbxTrace\Hook::wrap('frankenphp', $handler);
+}
+
 while (frankenphp_handle_request($handler)) {
     gc_collect_cycles();
 }
Exact detection rules

Package H2 (Long-running PHP), proposal H2:frankenphp, defined in hooks/php/h2/proposals/frankenphp.toml.

  • Image matches (regex): ^dunglas/frankenphp
  • Dependency on: runtime/frankenphp-symfony, laravel/octane
  • Where the change goes (regex): frankenphp_handle_request\s*\(

ReactPHP: request boundaries for the HTTP server ​

  • Use this when: PHP service that depends on react/http (in composer.json); a companion to H1:ext or H1:basic or H1:preload or H1:ffi.
  • Hub automation: not at all. The hub lists these steps with its proposal but changes nothing.
  • Check and undo: hook built into the service

Wraps the request handler given to React\Http\HttpServer: request_begin before it, request_end with the response status (after the promise settles for asynchronous handlers).

Source change, then rebuild:

  1. Wrap the last argument of new HttpServer(...) (the request handler): new HttpServer(\VbxTrace\Hook::wrap('react', $handler)).
  2. Keep the class_exists() guard: the service must run unchanged when the hook is reverted.

Example change on a sample service (hooks/php/h2/proposals/react.diff):

diff
--- a/server.php
+++ b/server.php
@@ -40,5 +40,10 @@
 };
 
+// vbxtrace (docs/hooks/h2.md): request boundaries. A no-op without the hook.
+if (class_exists(\VbxTrace\Hook::class, false)) {
+    $handler = \VbxTrace\Hook::wrap('react', $handler);
+}
+
 $http = new HttpServer($handler);
 $http->listen(new SocketServer('127.0.0.1:8080'));
Exact detection rules

Package H2 (Long-running PHP), proposal H2:react, defined in hooks/php/h2/proposals/react.toml.

  • Dependency on: react/http
  • Where the change goes (regex): new\s+(\\?React\\Http\\)?HttpServer\s*\(

RoadRunner: request boundaries in the PHP worker ​

  • Use this when: PHP service that depends on spiral/roadrunner-http, spiral/roadrunner or spiral/framework (in composer.json); a companion to H1:ext or H1:basic or H1:preload or H1:ffi.
  • Hub automation: not at all. The hub lists these steps with its proposal but changes nothing.
  • Check and undo: hook built into the service

Wraps the handler the worker loop calls for each PSR-7 request: request_begin/request_end with the client address and the response status.

Source change, then rebuild:

  1. Move the per-request code into a callable $handler(ServerRequestInterface): ResponseInterface, wrap it with \VbxTrace\Hook::wrap('roadrunner', $handler) and call it from the waitRequest() loop.
  2. Keep the class_exists() guard: the service must run unchanged when the hook is reverted.

Example change on a sample service (hooks/php/h2/proposals/roadrunner.diff):

diff
--- a/worker.php
+++ b/worker.php
@@ -40,6 +40,11 @@
 };
 
+// vbxtrace (docs/hooks/h2.md): request boundaries in the worker. A no-op without the hook.
+if (class_exists(\VbxTrace\Hook::class, false)) {
+    $handler = \VbxTrace\Hook::wrap('roadrunner', $handler);
+}
+
 while ($request = $psr7->waitRequest()) {
     try {
         $psr7->respond($handler($request));
Exact detection rules

Package H2 (Long-running PHP), proposal H2:roadrunner, defined in hooks/php/h2/proposals/roadrunner.toml.

  • Dependency on: spiral/roadrunner-http, spiral/roadrunner, spiral/framework
  • Files: .rr.yaml, .rr.yml, rr.yaml
  • Where the change goes (regex): ->waitRequest\(\)

Swoole / OpenSwoole: request context per coroutine ​

  • Use this when: PHP service that depends on swoole/ide-helper, openswoole/ide-helper, hyperf/framework or laravel/octane (in composer.json); a companion to H1:ext or H1:basic or H1:preload or H1:ffi.
  • Hub automation: not at all. The hub lists these steps with its proposal but changes nothing.
  • Check and undo: hook built into the service

Wraps the HTTP server's on('request') callback so each request gets a context bound to its coroutine (child coroutines inherit it).

Source change, then rebuild:

  1. Wrap the callback given to $server->on('request', ...): $h = \VbxTrace\Hook::wrap('swoole', $h, ['server' => $server]) (use 'openswoole' for OpenSwoole; the same adapter). Passing the server gives exact request indexes.
  2. Keep the class_exists() guard: the service must run unchanged when the hook is reverted.

Example change on a sample service (hooks/php/h2/proposals/swoole.diff):

diff
--- a/server.php
+++ b/server.php
@@ -20,5 +20,10 @@
     $response->end($body);
 };
 
+// vbxtrace (docs/hooks/h2.md): request context per coroutine. A no-op without the hook.
+if (class_exists(\VbxTrace\Hook::class, false)) {
+    $handler = \VbxTrace\Hook::wrap('swoole', $handler, ['server' => $server]);
+}
+
 $server->on('request', $handler);
 $server->start();
Exact detection rules

Package H2 (Long-running PHP), proposal H2:swoole, defined in hooks/php/h2/proposals/swoole.toml.

  • Image matches (regex): ^phpswoole/swoole, ^openswoole/swoole
  • Command matches (regex): \bphp\b.*\b(server|swoole)\.php
  • Dependency on: swoole/ide-helper, openswoole/ide-helper, hyperf/framework, laravel/octane
  • Files: *.php
  • Where the change goes (regex): ->on\(\s*["']request["']

Workerman: request boundaries per message ​

  • Use this when: PHP service that depends on workerman/workerman or workerman/webman-framework (in composer.json); a companion to H1:ext or H1:basic or H1:preload or H1:ffi.
  • Hub automation: not at all. The hub lists these steps with its proposal but changes nothing.
  • Check and undo: hook built into the service

Wraps the worker's onMessage callback: request_begin/request_end around each message, the index counted per connection.

Source change, then rebuild:

  1. Wrap the value assigned to $worker->onMessage: $worker->onMessage = \VbxTrace\Hook::wrap('workerman', $onMessage).
  2. Keep the class_exists() guard: the service must run unchanged when the hook is reverted.

Example change on a sample service (hooks/php/h2/proposals/workerman.diff):

diff
--- a/server.php
+++ b/server.php
@@ -30,4 +30,8 @@
 };
 
+// vbxtrace (docs/hooks/h2.md): request boundaries per message. A no-op without the hook.
+if (class_exists(\VbxTrace\Hook::class, false)) {
+    $onMessage = \VbxTrace\Hook::wrap('workerman', $onMessage);
+}
 $worker->onMessage = $onMessage;
Exact detection rules

Package H2 (Long-running PHP), proposal H2:workerman, defined in hooks/php/h2/proposals/workerman.toml.

  • Dependency on: workerman/workerman, workerman/webman-framework
  • Where the change goes (regex): ->onMessage\s*=

Add PHP's FFI extension to the image ​

  • Use this when: PHP service on the image php.
  • Hub automation: not at all. The hub lists these steps with its proposal but changes nothing.
  • Check and undo: hook built into the service

Dockerfile change for an official php image: builds ext-ffi so the preload or basic variant can be used. Needs network access during the image build; the extension variant (ext.toml) avoids this and is preferred.

Source change, then rebuild:

  1. alpine: after FROM add: RUN apk add --no-cache libffi && apk add --no-cache --virtual .vbx-build libffi-dev $PHPIZE_DEPS && docker-php-ext-install ffi && apk del .vbx-build
  2. debian: after FROM add: RUN apt-get update && apt-get install -y --no-install-recommends libffi-dev && docker-php-ext-install ffi && rm -rf /var/lib/apt/lists/*
  3. Then propose preload.toml (FPM/Apache) or basic.toml (CLI runtimes).

Example change on a sample service (hooks/php/h1/proposals/add-ffi.diff):

diff
--- a/Dockerfile
+++ b/Dockerfile
@@ -1,4 +1,7 @@
 FROM php:8.3-fpm-alpine
+# vbxtrace (docs/hooks/h1.md): PHP's FFI extension, for the runtime hook.
+RUN apk add --no-cache libffi && apk add --no-cache --virtual .vbx-build libffi-dev $PHPIZE_DEPS \
+ && docker-php-ext-install ffi && apk del .vbx-build
 COPY . /var/www/html
Exact detection rules

Package H1 (PHP process models (kernel)), proposal H1:add-ffi, defined in hooks/php/h1/proposals/add-ffi.toml.

  • Image matches (regex): ^(docker\.io/)?(library/)?php:
  • Files: Dockerfile

nginx: pass the request index and local port to PHP-FPM ​

  • Use this when: PHP service on the image nginx, trafex/php-nginx or webdevops/php-nginx; a companion to H1:ext or H1:preload or H1:ffi.
  • Hub automation: not at all. The hub lists these steps with its proposal but changes nothing.
  • Check and undo: hook built into the service

Optional, together with a PHP request-hook proposal: two fastcgi_param lines in the service's nginx config give the hook the request's number on the keep-alive connection and the accepted socket's port.

Source change, then rebuild:

  1. In every location block that has fastcgi_pass, after 'include fastcgi_params;', add: fastcgi_param VBXTRACE_CONNECTION_REQUESTS $connection_requests; and fastcgi_param VBXTRACE_LOCAL_PORT $server_port;
  2. Reload nginx (the change goes out with the next deploy).

Example change on a sample service (hooks/php/h1/proposals/nginx-params.diff):

diff
--- a/nginx/default.conf
+++ b/nginx/default.conf
@@ -10,6 +10,9 @@
     location ~ \.php$ {
         include fastcgi_params;
         fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
+        # vbxtrace (docs/hooks/h1.md): the request's number on the client connection and the local port.
+        fastcgi_param VBXTRACE_CONNECTION_REQUESTS $connection_requests;
+        fastcgi_param VBXTRACE_LOCAL_PORT $server_port;
         fastcgi_pass php:9000;
     }
 }
Exact detection rules

Package H1 (PHP process models (kernel)), proposal H1:nginx-params, defined in hooks/php/h1/proposals/nginx-params.toml.

  • Image matches (regex): ^nginx, ^trafex/php-nginx, ^webdevops/php-nginx
  • Files: nginx.conf, **/nginx/**/*.conf, **/default.conf, **/sites-enabled/*

Check that it works, and undo ​

Each block links the variant it needs.

Hook mounted into the container ​

Check: After the redeploy, this lists the processes that loaded the hook (empty: it is not loaded):

sh
docker compose exec app sh -c 'grep -l vbxtrace /proc/[0-9]*/maps'

The hub's Trace tab then shows links whose method starts with hook:.

Undo: Set VBXTRACE: "0" in the service's environment and restart it, or revert the commit (the hub's proposal screen has a revert per container). Remove the mount of /opt/vbxtrace only together with what loads from it: a runtime told to preload a missing file may refuse to start.

Hook built into the service ​

Check: After the rebuild, the binary carries the hook's probes (a count above 0):

sh
readelf -n <the built binary> | grep -c vbxtrace

The hub's Trace tab then shows links whose method starts with hook:.

Undo: Set VBXTRACE: "0" in the service's environment and restart it, or revert the change.