Skip to main content

Find the slow function in a Laravel page

Install the XHProf extension and the maantje/xhprof-buggregator-laravel package, then point it at Buggregator. This Laravel profiler sends each request's profile to Buggregator, where the Flamechart and Top functions tabs show which function takes the time, with no Blackfire or paid service.

Steps

1. Install the XHProf extension

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

2. Install the Laravel package

bash
composer require --dev maantje/xhprof-buggregator-laravel

3. Point it at Buggregator

Add the endpoint to .env. The profile is labeled with your app's name from APP_NAME. In Docker Compose, replace 127.0.0.1 with the Buggregator service name.

dotenv
PROFILER_ENDPOINT=http://profiler@127.0.0.1:8000

4. Turn profiling on

The package profiles only while this is set, so turn it off when you are done (package README: https://github.com/maantje/xhprof-buggregator-laravel). It profiles each HTTP request; for queues and commands, the README shows how to start the profiler yourself.

env
XHPROF_ENABLED=true

5. Load the page and read the profile

Open the slow page, then the profile in Buggregator. Flamechart shows where time is spent. Top functions ranks functions by CPU time, wall time, memory and call count. Call graph colors nodes from white to dark red: the darker, the more it costs.

Why it works

XHProf records CPU time, wall time and memory for every function call in the request. The package sends that data to Buggregator's profiler endpoint on port 8000, next to your exceptions and logs. After a fix, compare two runs side by side to check that it helped.

Checked on with Buggregator v2.8.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 →