Skip to main contentNedix.io

XHgui

A Docker image that includes the XHGui web interface, which can be used in conjunction with Xhprof to view PHP profiling data.

Setup

Install dependencies

composer require --dev perftools/php-profiler

Bootstrap code

bootstrap.php
$profiler = new \Xhgui\Profiler\Profiler([
'save.handler' => \Xhgui\Profiler\Profiler::SAVER_FILE,
'save.handler.file' => [
'filename' => '/mnt/files/xhprof/xhgui.data.jsonl',
],
]);
$profiler->start();

(*) Update configuration

If your application makes use of services that run on localhost you should adjust your configuration to use an alternative DNS name:

- localhost:3306
+ host.docker.internal:3306

Create Docker setup

docker-compose-xhgui.yml
version: "3.8"
services:
nginx-xhprof:
image: wodby/nginx:1.19
environment:
NGINX_VHOST_PRESET: php
NGINX_BACKEND_HOST: xhprof
NGINX_SERVER_ROOT: /var/www/html/public

Usage

Step 1.

Start the containers:

docker compose -f docker-compose.yml -f docker-compose-xhgui.yml up -d

Step 2.

Navigate to your page on localhost:8000 to capture the profiling data.

Step 3.

Execute the following command to load the data into XHGui:

docker compose -f docker-compose-xhgui.yml exec xhgui php /var/www/xhgui/external/import.php -f /data/xhprof/xhgui.data.jsonl

Step 4.

Find XHGui on localhost:8001.