Streaming php profiler (POC/WIP)
Find a file
2025-07-04 14:18:26 +02:00
furnace.php Initial profiler POC 2025-07-04 14:13:13 +02:00
LICENSE Add license 2025-07-04 14:18:26 +02:00
README.md Add README.md 2025-07-04 14:17:34 +02:00

PHP-Furnace

Proof of concept in alpha stage.

A near zero-dependency, PHP-FPM process profiler and live streaming dashboard. Designed for PHP 8.1+ using only standard libraries. It uses /proc, gdb, and Server-Sent Events to continuously trace live PHP-FPM processes but requires PHP to have pcntl extension to be enabled.


🚀 Features

  • Monitors all running PHP-FPM worker processes

  • Tracks:

    • Memory usage
    • CPU time and deltas
    • Number of open file descriptors
    • Number of threads
    • Last handled request URI (via $_SERVER['REQUEST_URI'])
    • Backtraces using GDB
  • Streams data live to the browser via SSE

  • Comes with a minimal HTML viewer

  • Logs data in newline-delimited JSON for later use


📦 Requirements

  • PHP 8.1 or later
  • Linux-based system (uses /proc and GDB)
  • gdb installed and executable by the current user
  • pcntl extension enabled
sudo apt install gdb

🛠️ Setup

  1. Ensure gdb and pcntl are available
  2. Run the script:
php furnace.php
  1. Open the live dashboard:
http://localhost:8123/

📁 Output Location

Log data is appended to:

/tmp/php-furnace/furnace-stream.log

Each event is streamed to the browser and formatted in JSON:

{
  "time": 1720043265,
  "delta": 5,
  "pid": 3410,
  "calls": 3,
  "cpu_time_ticks": 20199,
  "cpu_delta": 15,
  "memory_kb": 10240,
  "threads": 1,
  "fds": 23,
  "request_uri": "/index.php",
  "stack": ["#0 ...", "#1 ..."]
}

🧯 Troubleshooting

  • No data in the browser:

    • Check /tmp/php-furnace/furnace-stream.log for entries
    • Confirm PHP-FPM workers exist via ps aux | grep php-fpm
    • Ensure gdb is installed and accessible without blocking
  • GDB timeout:

    • Process may be idle or protected — increase timeout or skip slow PIDs