Laravel Herd Pro has a really slick SPX profiler integration. Unfortunately, at work I’m on a Ubuntu machine using a custom Docker container to run our app, so can’t take advantage of it.
We have one specific artisan command that takes many hours to run and I’m working on improving the performance.
I wanted to use SPX profiler to track down what was taking so long, and here’s how I got it to work.
Note: I know this is a bit of an unorthodox approach to using Docker containers, but it works for now…
Step-By-Step
- Run
docker compose exec www bash
to open a terminal inside the container - Install SPX following the directions (note: skip the
sudo
since we’re already running as a root user inside the container) - Edit
/usr/local/etc/php/php.ini
and add these lines to enable SPXextension = spx.so spx.http_enabled = 1 spx.http_key = "dev" spx.http_ip_whitelist = "*" spx.http_trusted_proxies = "*"
- Run
pkill -o -USR2 php-fpm
inside the container to restart the PHP service (thanks for the tip) - In a browser, visit
http://myapp.test/?SPX_KEY=dev&SPX_UI_URI=/
to visit the SPX Control Panel - Check the “Enabled” box
- Open a new tab and visit page or two on the app; refresh the SPX Control Panel and you should see the requests show up at the bottom
- Run the artisan command, prefixing it with a couple of env settings:
SPX_ENABLED=1 SPX_REPORT=full php artisan list
- Refresh the SPX Control Panel and inspect the results