Skip to main content

Profile Symfony APIs and workers

Install the XHProf extension and the velpl/buggregator-profiler-bundle package, then turn the bundle on. It profiles each HTTP request and each console command of your Symfony app and sends the profile to Buggregator. You get a call graph, a flame graph and a top functions table for JSON API calls, commands and Messenger workers. It works next to the Symfony web profiler.

Steps

1. Install the XHProf extension

bash
pear channel-update pear.php.net
pecl install xhprof

2. Install the bundle

Add it as a dev dependency.

bash
composer require --dev velpl/buggregator-profiler-bundle:^0.3

3. Turn it on

The bundle sends nothing until enabled is true. In Docker Compose, replace 127.0.0.1 with the Buggregator service name.

yaml
# config/packages/buggregator_profiler.yaml
buggregator_profiler:
    enabled: true
    application_name: 'My app'
    profiler_url: 'http://127.0.0.1:8000'

4. Call your API or run a command

Each main HTTP request is one profile, from the start of the request to its end. Each console command is one profile, from the start of the command to its end.

bash
curl http://127.0.0.1/api/orders
bin/console app:import-products

5. Give a worker an end

A worker is a console command too, so its profile is sent when it stops. Let it handle a few messages and exit.

bash
bin/console messenger:consume async --limit=10

6. Read the profile

Open http://127.0.0.1:8000 and pick the profile. Call graph colors nodes from white to dark red: the darker, the more it costs. Flame graph shows where the time goes. Top functions ranks functions by CPU time, wall time, memory and call count.

Why it works

XHProf records CPU time, wall time and memory for every function call. The bundle starts the profiler when a request or a command begins and sends the data to Buggregator when it ends. That is why it also covers code with no page to look at: JSON APIs, commands and workers.

Checked on with Buggregator v2.13.0

Setup in 60 seconds

No registration. No account. Start it and point your app at it.

1

Start Buggregator

One file, installed with one command. The web UI opens on port 8000. Prefer containers? Use the Docker tab.

$ curl -fsSL https://raw.githubusercontent.com/buggregator/server/master/scripts/install.sh | sh
$ HTTP_ADDR=127.0.0.1:8000 \
  SMTP_ADDR=127.0.0.1:1025 \
  VAR_DUMPER_ADDR=127.0.0.1:9912 \
  MONOLOG_ADDR=127.0.0.1:9913 \
  PROXY_ADDR=127.0.0.1:8080 \
  ~/.local/bin/buggregator

The script picks the file for your CPU: Intel/AMD or ARM.

One file for Linux, macOS and Windows, about 40 MB. Nothing else to install.

This run line keeps it on this computer. Without the *_ADDR settings it listens on all network interfaces

Rather not run a script? Download the file yourself

Runs on Windows, macOS and Linux, on Intel/AMD and ARM.

Prefer not to do it yourself? Your AI agent can set Buggregator up for you