merged branch tomglue/console_reregister_commands_fix (PR #8242)

This PR was submitted for the master branch but it was merged into the 2.2 branch instead (closes #8242).

Discussion
----------

[FrameworkBundle] do not re-register commands each time a Console\Application is run

| Q             | A
| ------------- | ---
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets |
| License       | MIT
| Doc PR        |

I have been experimenting with using the Symfony console application inside of a React event loop which works quite well.

In this scenario, I re-use an instances of a Console\Application to run multiple tasks. This works well apart from unnecessarily reloading the command classes from all included bundles each time doRun() is called (https://github.com/symfony/symfony/blob/master/src/Symfony/Bundle/FrameworkBundle/Console/Application.php#L68). This can also lead to running out of file descriptors under heavy load as bootstrap.php.cache uses a RecursiveDirectoryIterator to load the command.

Commits
-------

1983fc3 [FrameworkBundle] do not re-register commands each time a Console\Application is run
This commit is contained in:
Fabien Potencier 2013-06-13 09:04:56 +02:00
commit 3b068378e8
1 changed files with 6 additions and 1 deletions

View File

@ -27,6 +27,7 @@ use Symfony\Component\HttpKernel\Bundle\Bundle;
class Application extends BaseApplication
{
private $kernel;
private $commandsRegistered = false;
/**
* Constructor.
@ -65,7 +66,9 @@ class Application extends BaseApplication
*/
public function doRun(InputInterface $input, OutputInterface $output)
{
$this->registerCommands();
if (!$this->commandsRegistered) {
$this->registerCommands();
}
if (true === $input->hasParameterOption(array('--shell', '-s'))) {
$shell = new Shell($this);
@ -87,5 +90,7 @@ class Application extends BaseApplication
$bundle->registerCommands($this);
}
}
$this->commandsRegistered = true;
}
}