Contributed by
Maxime Steinhausser
in #23831.
The VarDumper component provides a dump()
function as a more advanced
alternative to PHP's var_dump()
function. The problem of dumping data from
your application is that, for example, when working on an API you might end up
in the console with a mix of your response data and the dumped data:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | classApiControllerextendsAbstractController{/** * @Route("/hello") */publicfunctionhello(Request$request,UserInterface$user){dump($request->attributes,$user);returnJsonResponse::create(['status'=>'OK','message'=>"Hello {$user->getUsername()}"]);}} |
In this case, the console output is confusing:

In order to solve these issues, in Symfony 4.1 we've introduced a dedicated
server to collect the dumped data. In practice you just need to run the newserver:dump
command and whenever you call to dump()
, the dumped data
is sent to a single centralized server that outputs it to the console or to a
file in HTML format:
1 2 3 4 5 6 | # displays the dumped data in the console:$ ./bin/console server:dump [OK] Server listening on tcp://0.0.0.0:9912# stores the dumped data in a file using the HTML format:$ ./bin/console server:dump --format=html > dump.html |
This is how the server looks when dumping contents to the console (which includes context information such as the source file, the HTTP request, the executed command, etc.):

And this is how it looks when using the HTML format:

When using it inside a Symfony application, the new server is configured in thedebug
package:
1 2 3 | # config/packages/dev/debug.yamldebug:dump_destination:"tcp://%env(VAR_DUMPER_SERVER)%" |