Skip to content

Commit 1a46605

Browse files
feature symfony#28298 [WebServerBundle] Add support for Xdebug's Profiler (maidmaid)
This PR was merged into the 4.2-dev branch. Discussion ---------- [WebServerBundle] Add support for Xdebug's Profiler | Q | A | ------------- | --- | Branch? | master | Bug fix? | no | New feature? | yes | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | / | License | MIT | Doc PR | / > Xdebug's Profiler is a powerful tool that gives you the ability to analyze your PHP code and determine bottlenecks or generally see which parts of your code are slow and could use a speed boost. https://xdebug.org/docs/profiler When we run/start the web server, it would be useful to enable the trigger for the Xdebug's Profiler. That means we could easily trigger the creation of a Xdebug profile and analysing it [thanks to PhpStorm](https://www.jetbrains.com/help/phpstorm/analyzing-xdebug-profiling-data.html) which provides an **Execution Statistics** panel (examine the summary information about execution metrics of every called function) and a **Call Tree** panel (explore the execution paths of all called functions). You can see these two panels in action [here](https://youtu.be/_ua_O01IICg?t=1m22s) for a better understanding. Commits ------- 0f4c0a6 Add support for Xdebug Profiler
2 parents d4e1cd9 + 0f4c0a6 commit 1a46605

File tree

3 files changed

+9
-1
lines changed

3 files changed

+9
-1
lines changed

src/Symfony/Bundle/WebServerBundle/Command/ServerRunCommand.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,9 @@ protected function execute(InputInterface $input, OutputInterface $output)
133133
$config = new WebServerConfig($documentRoot, $env, $input->getArgument('addressport'), $input->getOption('router'));
134134

135135
$io->success(sprintf('Server listening on http://%s', $config->getAddress()));
136+
if (ini_get('xdebug.profiler_enable_trigger')) {
137+
$io->comment('Xdebug profiler trigger enabled.');
138+
}
136139
$io->comment('Quit the server with CONTROL-C.');
137140

138141
$exitCode = $server->run($config, $disableOutput, $callback);

src/Symfony/Bundle/WebServerBundle/Command/ServerStartCommand.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,9 @@ protected function execute(InputInterface $input, OutputInterface $output)
144144

145145
if (WebServer::STARTED === $server->start($config, $input->getOption('pidfile'))) {
146146
$io->success(sprintf('Server listening on http://%s', $config->getAddress()));
147+
if (ini_get('xdebug.profiler_enable_trigger')) {
148+
$io->comment('Xdebug profiler trigger enabled.');
149+
}
147150
}
148151
} catch (\Exception $e) {
149152
$io->error($e->getMessage());

src/Symfony/Bundle/WebServerBundle/WebServer.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,9 @@ private function createServerProcess(WebServerConfig $config)
150150
throw new \RuntimeException('Unable to find the PHP binary.');
151151
}
152152

153-
$process = new Process(array_merge(array($binary), $finder->findArguments(), array('-dvariables_order=EGPCS', '-S', $config->getAddress(), $config->getRouter())));
153+
$xdebugArgs = ini_get('xdebug.profiler_enable_trigger') ? array('-dxdebug.profiler_enable_trigger=1') : array();
154+
155+
$process = new Process(array_merge(array($binary), $finder->findArguments(), $xdebugArgs, array('-dvariables_order=EGPCS', '-S', $config->getAddress(), $config->getRouter())));
154156
$process->setWorkingDirectory($config->getDocumentRoot());
155157
$process->setTimeout(null);
156158

0 commit comments

Comments
 (0)