Blackfire is a PHP profiler that helps you find bottlenecks in your code. It's a paid service, but you can get a free trial at blackfire.io.
Blackfire works by profiling your code as it runs.
A PHP extension must be installed into your PHP container. While the code is running, the PHP extension sends the profiling data to the (local) Blackfire agent container. The agent container processes the data and uploads it to the Blackfire.io website (where you can view the results).
By default, Blackfire is commented out (not everyone uses it). To enable:
- Edit your
.env
file- Fill in all Blackfire environment variables
- Enable the agent container by adding
opt/blackfire.yml
to theCOMPOSE_FILE
list
- Enable the Blackfire extension for PHP by uncommenting the
Install Blackfire
lines inphp/xx/Dockerfile
(where "xx" is the version of PHP you're enabling Blackfire for) - Rebuild and restart your containers:
docker compose build --pull --no-cache
docker compose up -d
- Sign into blackfire.io
- Install the Blackfire extension in your browser. Here's one for Google Chrome
- Navigate to the site/page you'd like to profile
- Click the 'Profile' button in the Blackfire browser extension
- Check the Blackfire extension is installed in your PHP container. Use
phpinfo()
to confirm. - Check the Blackfire agent (container) is running. Use
docker compose ps
to confirm. - Check your Blackfire environment variables are correct in
.env
.
The Blackfire documentation should have the answers you are looking for.