Skip to content
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed

Conversation

tomdmaguire
Copy link
Contributor

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.

@@ -65,7 +66,9 @@ public function getKernel()
*/
public function doRun(InputInterface $input, OutputInterface $output)
{
$this->registerCommands();
if(!$this->commandsRegistered){
Copy link
Member

Choose a reason for hiding this comment

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

missing whitespace after the if.

$this->registerCommands();
if (!$this->commandsRegistered) {
$this->registerCommands();
}

$this->setDispatcher($this->kernel->getContainer()->get('event_dispatcher'));
Copy link
Member

Choose a reason for hiding this comment

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

maybe the dispatcher may not need to be set each time as well?

fabpot added a commit that referenced this pull request Jun 13, 2013
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
@fabpot fabpot closed this Jun 13, 2013
fabpot added a commit that referenced this pull request Jun 13, 2013
* 2.2:
  Throw exception if value is passed to VALUE_NONE input, long syntax
  fixed date type format pattern regex
  [FrameworkBundle] tweaked previous merge (refs #8242)
  do not re-register commands each time a Console\Application is run
  [Process] moved env check to the Process class (refs #8227)
  fix issue where $_ENV contains array vals
  [DomCrawler] Fix handling file:// without a host
  [Form] corrected interface bind() method defined against in deprecation notice
  [Finder] Fix SplFileInfo::getContents isn't working with ssh2 protocol

Conflicts:
	src/Symfony/Component/Console/Tests/Input/ArgvInputTest.php
	src/Symfony/Component/DomCrawler/Link.php
	src/Symfony/Component/Form/Form.php
fabpot added a commit that referenced this pull request Jun 23, 2013
* 2.3: (33 commits)
  [Form] fixed INF usage which does not work on Solaris (closes #8246)
  Fix grammar
  Removed PHP 5.5 from the allowed failures.
  [Intl] Fixed tests failing on PHP 5.5
  bumped Symfony version to 2.2.4
  updated VERSION for 2.2.3
  update CONTRIBUTORS for 2.2.3
  updated CHANGELOG for 2.2.3
  [DependencyInjection] Replaced try/catch block with an @ExpectedException annotation in a test.
  [CssSelector] tweaked README file (closes #8287)
  added a node about HTML extension in readme
  [Console] Fixed the table rendering with multi-byte strings.
  Feature/fix unit tests
  [Process] Disable exception on stream_select timeout
  [HttpFoundation] fixed issue with session_regenerate_id (closes #7380)
  [DomCrawler] added a note about the default charset
  Throw exception if value is passed to VALUE_NONE input, long syntax
  fixed date type format pattern regex
  [Security] fixed usage of the salt for the bcrypt encoder (refs #8210)
  [FrameworkBundle] tweaked previous merge (refs #8242)
  ...

Conflicts:
	src/Symfony/Component/HttpKernel/Kernel.php
fabpot added a commit that referenced this pull request Jul 29, 2013
This PR was merged into the master branch.

Discussion
----------

[FrameworkBundle] fixed regression where the command might have the wrong container if the application is reused several times

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

This fixes a regression introduced in #8242. Before this PR, the commands were always getting the current container registered in the kernel. But as the commands are now registered only once, if the container changes, the commands were not aware of this change. That happens quite frequently in functional tests where the Kernel is booted and shutdown several times in the same process.

Commits
-------

1bd45b3 [FrameworkBundle] fixed regression where the command might have the wrong container if the application is reused several times
ostrolucky pushed a commit to ostrolucky/symfony that referenced this pull request Mar 25, 2018
* 2.3: (33 commits)
  [Form] fixed INF usage which does not work on Solaris (closes symfony#8246)
  Fix grammar
  Removed PHP 5.5 from the allowed failures.
  [Intl] Fixed tests failing on PHP 5.5
  bumped Symfony version to 2.2.4
  updated VERSION for 2.2.3
  update CONTRIBUTORS for 2.2.3
  updated CHANGELOG for 2.2.3
  [DependencyInjection] Replaced try/catch block with an @ExpectedException annotation in a test.
  [CssSelector] tweaked README file (closes symfony#8287)
  added a node about HTML extension in readme
  [Console] Fixed the table rendering with multi-byte strings.
  Feature/fix unit tests
  [Process] Disable exception on stream_select timeout
  [HttpFoundation] fixed issue with session_regenerate_id (closes symfony#7380)
  [DomCrawler] added a note about the default charset
  Throw exception if value is passed to VALUE_NONE input, long syntax
  fixed date type format pattern regex
  [Security] fixed usage of the salt for the bcrypt encoder (refs symfony#8210)
  [FrameworkBundle] tweaked previous merge (refs symfony#8242)
  ...

Conflicts:
	src/Symfony/Component/HttpKernel/Kernel.php
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants