Skip to main content

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.

bash
docker run --pull always \
  -p 127.0.0.1:8000:8000 \
  -p 127.0.0.1:9912:9912 \
  ghcr.io/buggregator/server:latest

2. Install Symfony VarDumper

Add it as a dev dependency. It gives you the global dump() and dd() functions.

bash
composer require --dev symfony/var-dumper

3. 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.

php
$_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.

php
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.

  • 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

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