dump() in Yii without breaking the page
To dump a variable in a Yii app without breaking the page or a JSON response, install Symfony VarDumper and set VAR_DUMPER_FORMAT=server and VAR_DUMPER_SERVER=127.0.0.1:9912 in your entry script. Every dump() call then goes to the Buggregator UI as an expandable tree, with the file and line it came from, and nothing is printed into your output.
Steps
1. Start Buggregator
Port 8000 is the web UI, port 9912 receives the dumps.
docker run --pull always \
-p 127.0.0.1:8000:8000 \
-p 127.0.0.1:9912:9912 \
ghcr.io/buggregator/server:latest2. Install Symfony VarDumper
Add it as a dev dependency. It gives you the global dump() and dd() functions.
composer require --dev symfony/var-dumper3. Point VarDumper at Buggregator
Set two values at the top of your entry script, for example web/index.php in the Yii2 basic template. Add the same lines to the yii console script if you want dumps from commands too.
$_SERVER['VAR_DUMPER_FORMAT'] = 'server';
$_SERVER['VAR_DUMPER_SERVER'] = '127.0.0.1:9912';In Docker Compose, replace 127.0.0.1 with the Buggregator service name, for example buggregator:9912.
4. Call dump()
Use Symfony's dump() function in a controller, a model or a view. This is not yii\helpers\VarDumper::dump(), which is Yii's own helper.
public function actionView(int $id): Response
{
$order = Order::findOne($id);
dump($order->attributes);
return $this->asJson($order);
}Open http://127.0.0.1:8000. The dump shows there with the file and line. The JSON response stays valid.
5. Stop the script when you need to
dd() is sent to Buggregator too, but it still stops the script, as it always does.
Why it works
VarDumper reads VAR_DUMPER_FORMAT from $_SERVER the first time you call dump(). With server, it sends each dump over TCP to the address in VAR_DUMPER_SERVER instead of printing it. Buggregator listens on port 9912 and renders what arrives. One limit: on the Windows binary, the VarDumper module (port 9912) does not work.
Related tips
- Dumps
dump() without breaking your page or JSON response
Send Symfony VarDumper output to Buggregator with two env vars. dump() stops landing in your HTML or JSON and shows the file and line it came from.
- Dumps
Dump from any PHP script with Trap, no Docker
Add buggregator/trap with Composer, run vendor/bin/trap --ui and call trap() in a plain PHP script. Dumps show in a local web UI, not in your output.
- Mail
Yii2 mailer to a local inbox
Give the Yii2 Symfony Mailer an smtp://127.0.0.1:1025 DSN and turn off useFileTransport. Every email lands in Buggregator; nothing is delivered.
Checked on with Buggregator v2.13.0