Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[VarDumper] Introduce a new way to collect dumps through a server dumper#23831

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
fabpot merged 3 commits intosymfony:masterfromogizanagi:feature/server_dump
Mar 23, 2018
Merged

[VarDumper] Introduce a new way to collect dumps through a server dumper#23831

fabpot merged 3 commits intosymfony:masterfromogizanagi:feature/server_dump
Mar 23, 2018

Conversation

@ogizanagi
Copy link
Contributor

@ogizanagiogizanagi commentedAug 8, 2017
edited
Loading

QA
Branch?4.1
Bug fix?no
New feature?yes
BC breaks?no
Deprecations?no
Tests pass?yes
Fixed tickets#22987
LicenseMIT
Doc PRTODOsymfony/symfony-docs#9474

Could also be interesting as alternate solution for#23442.

Inspired by theServerLogHandler and@nicolas-grekas'scomment in#22987.


Description

This PR introduces a newserver:dump command available in theVarDumper component.
Conjointly with a newServerDumper data dumper, it allows to send serializedData clones to a single centralized server, in charge of dumping them on CLI output, or in an file in HTML format.

Showcase

HTTP calls

For instance, when working on an API and dumping something, you might end up with a mix of your response and the CLI dumped version of the data you asked:

class HelloControllerextends AbstractController{/**     * @Route("/hello")     */publicfunctionhello(Request$request,UserInterface$user)    {dump($request->attributes,$user);return JsonResponse::create(['status' =>'OK','message' =>"Hello{$user->getUsername()}"        ]);    }}

screenshot 2017-08-08 a 16 44 24

You might even get the HTML dump versionunder some conditions.

Dumping to a server allows collecting dumps in a separate place:

server-dump-http-to-cli

⚠️ By swallowing the previous dumpers output, the dump data collector is not active when running the dump server. Disable swallowing if you want both. ➜ Dumps are still collected in the profiler thanks tof24712e

CLI calls

The best probably is (to me) that you can also debug CLI applications...

server-dump-cli

...and get HTML formatted dumps:

server-dumper-cli-to-html-output

hence, benefit from all the features of this format (collapse, search, ...)

HTML output at a glance

screenshot 2017-08-11 a 19 28 25

The HTML output benefits from all theHtmlDumper features and contains extra informations about the context (sources, requests, command line, ...). It doesn't aim to replace the profiler for HTTP calls with the framework, but is really handy for CLI apps or by wiring it in your own web app, out of the framework usage.

CLI output at a glance

screenshot 2017-08-11 a 19 52 57

Usage within the framework

Config

For instance, in dev config:

#config/packages/dev/debug.yamldebug:dump_destination:"tcp://%env(VAR_DUMPER_SERVER)%"

The configuration also allows to set ahost option, but there is already a sensible default value (tcp://0.0.0.0:9912) so you don't have to deal with it.
In case you want to change the default host value used, simply use theVAR_DUMPER_SERVER env var.

When the server is running, all dumps are collected by the server and previous dumpers ones are "swallowed"by default. If you want both to collect dumps on the server AND keep previous dumpers on regular outputs, you can disable swallowing:

When the server isn't running or in case of failure to send the data clones to the server, the server dumper will delegates to the configured wrapped dumper, so dumps are displayed and collected as usual.

Running the server

bin/console server:dump [--format=cli|html]

Options

  • Theoutput option defaults tonull which will display dumps on CLI. It accepts a file path in which dumps will be collected in HTML format.

  • Theformat option allows to switch format to use. For instance, use thehtml format and redirect the output to a file in order to open it in your browser and inspect dumps in HTML format.

  • The defaulthost value is the same as the one configured under thedebug.server_dump.host config option, so you don't have to deal with it in most cases.
    In case you want to change the default host value used, simply use theVAR_DUMPER_SERVER env var (when using the debug bundle integration):

    VAR_DUMPER_SERVER=0.0.0.0:9204 bin/console server:dump

Manual wiring

If you want to wire it yourself in your own project or using it to inspect dumps as html before the kernel is even boot for instance:

$host ='0.0.0.0:9912';$cloner =newVarCloner();$dumper =newServerDumper($host,newCliDumper());VarDumper::setHandler(function ($var)use ($dumper,$cloner) {$dumper->dump($cloner->cloneVar($var));});

Create your own server app

The component already provides a default server app by means of theServerDumpCommand, but
you could also build your own by using theDumpServer:

$host ='0.0.0.0:9912';$server =newDumpServer($host);$server->start();$server->listen(function (Data$data,array$context,$clientId) {// do something});

jvasseur, yceruto, apfelbox, fancyweb, nicolas-grekas, Koc, maidmaid, reypm, jderusse, tristanbes, and 26 more reacted with thumbs up emojinicolas-grekas, skigun, mykiwi, yceruto, OskarStark, GeoffreyHervet, theofidry, antonmedv, birkof, chr-hertel, and 7 more reacted with heart emoji
@stof
Copy link
Member

stof commentedAug 8, 2017

disabling dumps from the data collector by default may not be a good idea.

@ogizanagi
Copy link
ContributorAuthor

disabling dumps from the data collector by default may not be a good idea.

f24712e might be a solution to this.

@ogizanagi
Copy link
ContributorAuthor

Last updates from yesterday (I've update the PR description & screens) with features I expected to add in a another PR, but here we are:

  • extracted theDumpServer in a dedicated class. SoServerDumpCommand is a server app consuming it and everyone could create its own app easily if he wants. So someone could imagine a full-featured app starting a dump server and exposing an http server to display the live stream of dumps, with more capabilities than the the simple html file provided in this PR.
  • introduced context providers as simple callables, which allows to add context to collected dumps.
  • enhanced the cli & html outputs with these new informations (cf screens).
  • mentioned how to manually wire the server dumper in the PR description.

->end()
->arrayNode('server_dump')->canBeEnabled()
->children()
->scalarNode('host')->defaultValue('tcp://0.0.0.0:9912')->end()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

I would not make this configurable in the config but as an env var. Like for the web server, imagine a scenario where you are working on many projects in parallel. It's easier to tweak an env var from the outside. Also, if the server is not a Symfony app, having the server address as an env var helps as well :)

ogizanagi reacted with thumbs up emoji
Copy link
ContributorAuthor

@ogizanagiogizanagiAug 12, 2017
edited
Loading

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Indeed, great idea. Done inb002175

{
$this
->setName('server:dump')
->addOption('host',null, InputOption::VALUE_REQUIRED,'The server host',$this->defaultHost)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

If you agree with the config removal, this should also read from the env var.

Copy link
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Option removed in favor of using the env var.

* use
* @param callable[] $contextProviders Callables indexed by name returning a context array
*/
publicfunction__construct($host,DataDumperInterface$wrappedDumper =null,$swallows =true,array$contextProviders =array())
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

$host would then accept an empty string, which would make it read the env var.

Copy link
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

I usednull instead of an empty string for now. Any reason to favor the empty string?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

null is perfect ofc

*/
class DumpServer
{
constHOST_ENV_VAR ='VAR_DUMPER_SERVER';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

why not inject with%env()% and keep this at the config level..

Copy link
ContributorAuthor

@ogizanagiogizanagiAug 12, 2017
edited
Loading

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Yes, we could leverage Symfony's env support for this, hence no need for the previous commit. But the rational here to me is that you probably don't need to make the env var itself configurable and when working with multiple projects (even ones not using the DebugBundle), you don't have to ensure the same env var is used. Just set it and it works out of the box.

Still, that'll be the most flexible and would avoid hardcoding this behavior, while we could just configure in the standard-edition and flex recipe:

parameters:env(VAR_DUMPER_SERVER):'tcp://0.0.0.0:9912'debug:server_dump:host:'%env(VAR_DUMPER_SERVER)%'

(or directly in DebugBundle'sservices.xml, as stated below indeed. No need for thedebug.server_dump.host option. But that'll still only work out of the box if you use the DebugBundle)

@fabpot : What do you think?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

note we dont need debug.server_dump.host per se, it can be done directly in services.xml

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

I don't see the need to change the env var name.

@ogizanagi
Copy link
ContributorAuthor

ogizanagi commentedAug 21, 2017
edited
Loading

I've brought some new changes and added some tests. The PR is ready on my side.
Tough part is the wiring with the framework and theDumpDataCollector. Hopefully I did it right, as much as possible. 🤞

deps=high failure is expected.
I might need some hints on the HHVM & AppVeyor failures, somehow related to thePhpProcess usage (and wrong working dir)?

Fixed on HHVM build, probably not the best way.The failure still remains on AppVeyor but is different:

"stream_socket_client(): unable to connect to tcp://0.0.0.0:9912 (The requested address is not valid in its context.)"

Fixed on AppVeyor by settingVAR_DUMPER_SERVER to use127.0.0.1 as AppVeyor seems to dislike0.0.0.0

Copy link
Member

@nicolas-grekasnicolas-grekas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

that's interesting, I need to checkout and play with it for better feedback :)

"ext-iconv":"*",
"twig/twig":"~1.34|~2.4"
"twig/twig":"~1.34|~2.4",
"symfony/process":"~3.4|~4.0"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

alpha order :)

ogizanagi reacted with thumbs up emoji
*
* @author Maxime Steinhausser <maxime.steinhausser@gmail.com>
*
* @final since version 3.4

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

just@final (since version 3.4 suggests is existed before, which is not the case)

ogizanagi reacted with thumbs up emoji
@fabpotfabpot mentioned this pull requestAug 24, 2017
if ($this->logger) {
$this->logger->warning('Unable to decode a message from {clientId} client.',array(
'clientId' =>$clientId,
));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Should be on one line (I haven't checked if you have other occurrences of similar lines).

Copy link
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Fixed

$payload =unserialize(base64_decode($message));

// Impossible to decode the message, give up.
if (false ===$payload) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

That does not work if you send a message that is not base64 encoded. PHP will vail out on line 65.

Copy link
ContributorAuthor

@ogizanagiogizanagiAug 24, 2017
edited
Loading

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

base64_decode won't fail on a non base64 encoded string AFAIK, butunserialize will trigger a notice. I think silencing it is enough but let me know.

{
$this
->setName('server:dump')
->addOption('output',null, InputOption::VALUE_REQUIRED,'An file path to save dumped data in html format, or null to display on CLI output.')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

A file ...

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

What about allowing to dump on STDOUT? Which means that everything else should be sent to STDERR.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

HTML, not html

Copy link
ContributorAuthor

@ogizanagiogizanagiAug 24, 2017
edited
Loading

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

What about allowing to dump on STDOUT? Which means that everything else should be sent to STDERR.

Using STDERR for command titles & comments is a fair point, I did it.

For dumps, the CliDumper will already use STDOUT. I also kept the context informations on STDOUT.

Or did you actually mean removing the--output option in favor of automatically using the HtmlDumper in the case of the output being redirected to a file or piped?
AFAIK, the only simple way to tell that is by usingposix_isatty, which won't be available on Windows (or perhapsfstat mode, but not sure about this being reliable on Windows neither).

Copy link
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

What about replacing the--output option by a--format option and extract processing in proper descriptors? It would let the user redirect or pipe the output and may allow other streamable formats like json-text-sequence to be implemented next.
Extracting descriptors from the command might also answer#23831 (comment) by allowing reuse and easing tests.

Copy link
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Done.

$this->filesystem->appendToFile($outputFile,sprintf('<style>%s</style><script>%s</script>',self::$style,self::$javascript));
}

$io->comment(sprintf('Consult collected dumps in html format by opening "%s" in your browser.',realpath($outputFile)));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

I let you change html to HTML everywhere :)

Copy link
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Fixed 😄

*/
class ServerDumpCommandextends Command
{
privatestatic$style = <<<'CSS'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

I would store the styles in a file underResources/ so that it's more easily reusable.

Copy link
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Still something useful considering#23831 (comment) ?

Copy link
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Done.

}
CSS;

privatestatic$javascript = <<<'JS'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Same for this piece of JS.

fabpot
fabpot previously requested changesAug 24, 2017
});
}

privatefunctiondisplayDumpCli(SymfonyStyle$io,Data$data,array$context,$clientId)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

If I'm creating my own server (like explained in the PR description), I would probably like to be able to reuse the logic in those 2 private methods, right?

Copy link
ContributorAuthor

@ogizanagiogizanagiAug 24, 2017
edited
Loading

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

I consider this command as a final application, not meant to be extended. That's why I also made it@final.

If someone wants to create his own server app, he'll probably want to integrate dumps his own way in his application and won't reuse theServerDumpCommand output. He'll create his own script collecting & processing dumps (perhaps by dumping it into a json file to be consumed by a ReactJS application for instance) using theDumpServer class.

@ogizanagi
Copy link
ContributorAuthor

ogizanagi commentedSep 24, 2017
edited
Loading

Last update: remove the--output option in favor of using--format=html|cli and redirecting the output to a file.

Feature freeze is coming very soon.
Would you have some time to play with this@nicolas-grekas ? :)

@ogizanagiogizanagi dismissedfabpot’sstale reviewSeptember 27, 2017 20:13

Requested changes done

@fabpot
Copy link
Member

I'd like to test it more thoroughly. Let's move it to 4.1.

@ogizanagi
Copy link
ContributorAuthor

ogizanagi commentedMar 11, 2018
edited
Loading

I may be a bit late to the party considering the upcoming 4.1 feature freeze. But in any case, this is now rebased, using PHP 7.1 features and tested on a 4.1 app. Everything still working fine :)

Tests failures are unrelated (see#26489).

theofidry reacted with thumbs up emoji

@antonmedv
Copy link

Will be cool to have it. Like output on rails or elixir/phoenix apps.

@javiereguiluzjaviereguiluz added the ❄️ Feature FreezeImportant Pull Requests to finish before the next Symfony "feature freeze" labelMar 12, 2018
@ogizanagi
Copy link
ContributorAuthor

ogizanagi commentedMar 22, 2018
edited
Loading

If I may dream a bit, I'd like to be able to run server:run-all and have server:run, server:log and server:dump in the same console (we could add webpack dev server to the list :) )
I would also love to replace the --format=html option by a proper webserver I could point my browser at, and see the live feed of dumps (and logs, etc.) in this tab.

When I started this PR, I also have in mind to provide a full featured web & cli app to centralize dumps & logs, but didn't take enough time yet to experiment it. Anyway this PR is already a big step to me, and I already have some other small improvements to come first in order to help using it easily on any context.

Btw, you don't use the source context in the CLI/HTML. Don't you want to add some source code excerpt there?

Currently, code excerpts are only retrieved by the SourceContextProvider for twig template. Being able to always getting the excerpt would require duplicating some logic from the twig bridge CodeExtension (or allow the HtmlDescriptor to use Twig and this extension fi available). I didn't want to pollute more this PR. So I'd suggest to try adding it into another PR :)

In the CLI, what about displaying the link to the file? cannot be an IDE link, but still a web link is possible (e.g.http://127.0.0.1:8000/_profiler/open?file=src/Controller/HelloController.php&line=15#line15)

Actually, it's the reverse: cannot be a web link for a cli command (no context available). But IDE link works great for both web requests & cli commands:

capture d ecran 2018-03-22 a 16 35 16

Oh btw, the HTML view is missing a date (and maybe the controller also, as displayed on the CLI):

I guess you've missed it 😄 It's already displayed on the top right:

capture d ecran 2018-03-22 a 16 36 51

About the controller, I'd suggest to polish and add it into another PR. Right now I'm not sure where to display it and don't want to pollute more this PR.

Thanks everyone for your reviews.

&$this->clonesCount,
);

$this->sourceContextProvider =newSourceContextProvider($this->charset);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

this defeats dependency injection, that's why I proposed to get it through$serverDumper

@symfonysymfony deleted a comment fromogizanagiMar 22, 2018
*/
finalclass RequestContextProviderimplements ContextProviderInterface
{
/** @var RequestStack */

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

can be removed

ogizanagi reacted with thumbs up emoji
@nicolas-grekas
Copy link
Member

@ogizanagi FYI I've forked your branch inhttps://github.com/nicolas-grekas/symfony/tree/feature/server_dump - the first commit is your PR squashed, the second are some tweaks I'd like to merge here when ready. They break the feature for now, but I think you can get the idea. If you want to take over, please tell :)

@ogizanagi
Copy link
ContributorAuthor

ogizanagi commentedMar 22, 2018
edited
Loading

@nicolas-grekas : Here you are.

The changes made to the data collector were indeed the ones I tried today, so let me explain:
What was bothering me was the inconsistency between the behaviors with API calls when you set thedebug.dump_destination totcp://* and anything else:
In the first case, even if the dump server isn't running, no more dump output appears in the response, while withdebug.dump_destination set to anything else or null (i.e no server dumper <=> current behavior) cli dumps appears in the output.
As stated in the PR description, getting a mix of your response and the cli dumped version of the data you asked is a mess, but at least you know it's there.
Probably that I'm overthinking this and this behavior should have been considered undesirable in the first place...

I also added a placeholder command in the debug bundle to easy discovery of the feature as you asked.

Finally, I'm not really satisfied by the newVAR_DUMPER_SERVER env var handling. But you already heard the argumentshere.

@fabpot
Copy link
Member

@ogizanagi Do you think you will have time (perhaps this week-end) to take comments into account (if not, someone can probably take over)? I would love to merge it for 4.1.

@ogizanagi
Copy link
ContributorAuthor

@fabpot : I've already taken all the comments into account & cherry-picked Nicolas' commit. This is already ready (at least for another round of reviews).

Copy link
Member

@fabpotfabpot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

with minor comments


protectedfunctionexecute(InputInterface$input,OutputInterface$output)
{
(newSymfonyStyle($input,$output))->getErrorStyle()->warning('In order to use the VarDumper server, set the debug.dump_destination config option to "tcp://%env(VAR_DUMPER_SERVER)%"');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Can you quote (") debug.dump_destination?

->scalarNode('dump_destination')
->info('A stream URL where dumps should be written to')
->example('php://stderr')
->example('php://stderr, or tcp://%env(VAR_DUMPER_SERVER)% when using the `server:dump` command')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Can you use" instead of `?

* added a`ServerDumper` to send serialized Data clones to a server
* added a`ServerDumpCommand` and`DumpServer` to run a server collecting
and displaying dumps on a single place with multiple formats support
* added`CliDescriptor` and`HtmlDescriptor` descriptors for`server:dump` cli and html formats support
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

CLI and HTML formats

$availableFormats =implode(',',array_keys($this->descriptors));

$this
->addOption('format',null, InputOption::VALUE_REQUIRED,"The output format ($availableFormats)",'cli')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

you should usesprintf here.

@ogizanagi
Copy link
ContributorAuthor

@fabpot : Fixed & squashed (I've kept Nicolas' commit and the next one finishing it).

antonmedv reacted with thumbs up emoji

@fabpot
Copy link
Member

Thank you@ogizanagi.

ogizanagi and yceruto reacted with hooray emoji

@fabpotfabpot merged commit138dad6 intosymfony:masterMar 23, 2018
fabpot added a commit that referenced this pull requestMar 23, 2018
…gh a server dumper (ogizanagi, nicolas-grekas)This PR was merged into the 4.1-dev branch.Discussion----------[VarDumper] Introduce a new way to collect dumps through a server dumper| Q             | A| ------------- | ---| Branch?       | 4.1 <!-- see comment below -->| Bug fix?      | no| New feature?  | yes <!-- don't forget updating src/**/CHANGELOG.md files -->| BC breaks?    | no| Deprecations? | no <!-- don't forget updating UPGRADE-*.md files -->| Tests pass?   | yes| Fixed tickets |#22987 <!-- #-prefixed issue number(s), if any -->| License       | MIT| Doc PR        | todo <!--highly recommended for new features-->Could also be interesting as alternate solution for#23442.Inspired by the [`ServerLogHandler`](#21080) and@nicolas-grekas's [comment](#22987 (comment)) in#22987.---## DescriptionThis PR introduces a new `server:dump` command available in the `VarDumper` component.Conjointly with a new `ServerDumper` data dumper, it allows to send serialized `Data` clones to a single centralized server, in charge of dumping them on CLI output, or in an file in HTML format.## Showcase### HTTP callsFor instance, when working on an API and dumping something, you might end up with a mix of your response and the CLI dumped version of the data you asked:```phpclass HelloController extends AbstractController{    /**     *@route("/hello")     */    public function hello(Request $request, UserInterface $user)    {        dump($request->attributes, $user);        return JsonResponse::create([            'status' => 'OK',            'message' => "Hello {$user->getUsername()}"        ]);    }}```<img width="732" alt="screenshot 2017-08-08 a 16 44 24" src="https://user-images.githubusercontent.com/2211145/29077731-0b2152d6-7c59-11e7-99dd-2d060a906d48.PNG">You might even get the HTML dump version [under some conditions](https://github.com/symfony/symfony/blob/master/src/Symfony/Component/HttpKernel/DataCollector/DumpDataCollector.php#L146-L157).Dumping to a server allows collecting dumps in a separate place:<!--![server-dumper-http-to-cli-output](https://user-images.githubusercontent.com/2211145/29077977-8ace19ce-7c59-11e7-998e-ee9c49e67958.gif)-->![server-dump-http-to-cli](https://user-images.githubusercontent.com/2211145/29226044-dcc95f12-7ed0-11e7-8343-40aeb7b18dd5.gif)~⚠️ By swallowing the previous dumpers output, the dump data collector is not active when running the dump server. Disable swallowing if you want both.~ ➜ Dumps are still collected in the profiler thanks tof24712e### CLI callsThe best probably is (to me) that you can also debug CLI applications...![server-dump-cli](https://user-images.githubusercontent.com/2211145/29225951-84e29098-7ed0-11e7-8067-abaa9c50d169.gif)<!--![server-dumper-cli-to-cli-output](https://user-images.githubusercontent.com/2211145/29078261-1eb950ea-7c5a-11e7-94ee-aa3ae3bf7fb0.gif)-->...and get HTML formatted dumps:![server-dumper-cli-to-html-output](https://user-images.githubusercontent.com/2211145/30784609-d7dc19b8-a158-11e7-9b11-88ae819cfcca.gif)<!--![server-dump-cli-to-html](https://user-images.githubusercontent.com/2211145/29225866-2b5675e4-7ed0-11e7-98eb-339611bd94a7.gif)--><!--![server-dumper-cli-to-html-output](https://user-images.githubusercontent.com/2211145/29078247-17e33e5c-7c5a-11e7-94f7-47de6774e0e8.gif)-->hence, benefit from all the features of this format (collapse, search, ...)### HTML output at a glance<img width="831" alt="screenshot 2017-08-11 a 19 28 25" src="https://user-images.githubusercontent.com/2211145/29225513-eae349f2-7ece-11e7-9861-8cda9e80ba7f.PNG">The HTML output benefits from all the `HtmlDumper` features and contains extra informations about the context (sources, requests, command line, ...). It doesn't aim to replace the profiler for HTTP calls with the framework, but is really handy for CLI apps or by wiring it in your own web app, out of the framework usage.### CLI output at a glance<img width="829" alt="screenshot 2017-08-11 a 19 52 57" src="https://user-images.githubusercontent.com/2211145/29225482-c24afe18-7ece-11e7-8e83-d019b0d8303e.PNG">## Usage within the framework### ConfigFor instance, in your `config_dev.yml`:```yml#config_dev.ymldebug:    server_dump: true```or in your `config.yml`:```yml#config.ymldebug:    server_dump: '%kernel.debug%'```~~The configuration also allows to set a `host` option, but there is already a sensible default value (`tcp://0.0.0.0:9912`) so you don't have to deal with it.~~ Sinceb002175, in case you want to change the default host value used, simply use the `VAR_DUMPER_SERVER` env var.When the server is running, all dumps are collected by the server and previous dumpers ones are "swallowed" ~~by default. If you want both to collect dumps on the server AND keep previous dumpers on regular outputs, you can disable swallowing:~~<!--```ymldebug:    server_dump:        swallow: false```-->When the server isn't running or in case of failure to send the data clones to the server, the server dumper will delegates to the configured wrapped dumper, so dumps are displayed and collected as usual.### Running the server```bashbin/console server:dump [--format=cli|html]```#### Options- ~~The `output` option defaults to `null` which will display dumps on CLI. It accepts a file path in which dumps will be collected in HTML format.~~- The `format` option allows to switch format to use. For instance, use the `html` format and redirect the output to a file in order to open it in your browser and inspect dumps in HTML format.- ~~The default `host` value is the same as the one configured under the `debug.server_dump.host` config option, so you don't have to deal with it in most cases.~~    Sinceb002175, in case you want to change the default host value used, simply use the `VAR_DUMPER_SERVER` env var:    ```bash    VAR_DUMPER_SERVER=0.0.0.0:9204 bin/console server:dump    ```## Manual wiringIf you want to wire it yourself in your own project or using it to inspect dumps as html before the kernel is even boot for instance:```php$host = 'tcp://0.0.0.0:9912'; // use null to read from the VAR_DUMPER_SERVER env var$cloner = new VarCloner();$dumper = new ServerDumper($host, new CliDumper());VarDumper::setHandler(function ($var) use ($dumper, $cloner) {    $dumper->dump($cloner->cloneVar($var));});```## Create your own server appThe component already provides a default server app by means of the `ServerDumpCommand`, but you could also build your own by using the `DumpServer`:```php$host = 'tcp://0.0.0.0:9912'; // use null to read from the VAR_DUMPER_SERVER env var$server = new DumpServer($host);$server->start();$server->listen(function (Data $data, array $context, $clientId) {    // do something});```Commits-------138dad6 [VarDumper] Some tweaks after Nicolas' commit & ServerDumperPlaceholderCommand088c52e [VarDumper] Review config to use debug.dump_destination & tweak data collector3db1404 [VarDumper] Introduce a new way to collect dumps through a server dumper
@ogizanagiogizanagi deleted the feature/server_dump branchMarch 23, 2018 09:21
fabpot added a commit that referenced this pull requestMar 27, 2018
… at any time (ogizanagi)This PR was merged into the 4.1-dev branch.Discussion----------[VarDumper] Provide binary, allowing to start a server at any timeas soon as the "symfony/var-dumper" & "symfony/console" components are available.| Q             | A| ------------- | ---| Branch?       | master <!-- see below -->| Bug fix?      | no| New feature?  | yes <!-- don't forget to update src/**/CHANGELOG.md files -->| BC breaks?    | no     <!-- seehttps://symfony.com/bc -->| Deprecations? | no <!-- don't forget to update UPGRADE-*.md and src/**/CHANGELOG.md files -->| Tests pass?   | yes    <!-- please add some, will be required by reviewers -->| Fixed tickets | N/A   <!-- #-prefixed issue number(s), if any -->| License       | MIT| Doc PR        | TODOsymfony/symfony-docs#9474Now that#23831 is merged, there is still room for improvements we can bring during the stabilization months.Here is a first one: providing a simple CLI binary allows to easily start a server from any project (or even globally), just by having the var dumper & console packages in your deps.Commits-------eef10b1 [VarDumper] Provide binary, allowing to start a server at any time
@fabpotfabpot mentioned this pull requestMay 7, 2018
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@nicolas-grekasnicolas-grekasnicolas-grekas requested changes

@stofstofstof left review comments

@fabpotfabpotfabpot approved these changes

@ycerutoycerutoyceruto approved these changes

@chalasrchalasrchalasr approved these changes

+1 more reviewer

@ro0NLro0NLro0NL left review comments

Reviewers whose approvals may not affect merge requirements

Assignees

No one assigned

Labels

DebugBundleFeature❄️ Feature FreezeImportant Pull Requests to finish before the next Symfony "feature freeze"Status: ReviewedVarDumper

Projects

None yet

Milestone

4.1

Development

Successfully merging this pull request may close these issues.

11 participants

@ogizanagi@stof@fabpot@antonmedv@nicolas-grekas@sroze@ro0NL@yceruto@chalasr@javiereguiluz@carsonbot

[8]ページ先頭

©2009-2025 Movatter.jp