Skip to content

[Console] Added a way to set the process title #9780

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

Merged
merged 1 commit into from
Dec 18, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/Symfony/Component/Console/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
CHANGELOG
=========

2.5.0
-----

* added a way to set the process name of a command

2.4.0
-----

Expand Down
30 changes: 30 additions & 0 deletions src/Symfony/Component/Console/Command/Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ class Command
{
private $application;
private $name;
private $processName;
private $aliases = array();
private $definition;
private $help;
Expand Down Expand Up @@ -212,6 +213,16 @@ protected function initialize(InputInterface $input, OutputInterface $output)
*/
public function run(InputInterface $input, OutputInterface $output)
{
if (null !== $this->processName) {
if (function_exists('cli_set_process_title')) {
cli_set_process_title($this->processName);
} elseif (function_exists('setproctitle')) {
setproctitle($this->processName);
Copy link
Contributor

Choose a reason for hiding this comment

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

Given the problems with setproctitlepointed out in cli_set_process_title RFC (https://wiki.php.net/rfc/cli_process_title), is it really wise to use this?

Copy link
Member Author

Choose a reason for hiding this comment

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

We used to use both function, and we have no issue with theses.

} elseif (OutputInterface::VERBOSITY_VERY_VERBOSE === $output->getVerbosity()) {
$output->writeln('<comment>Install the proctitle PECL to be able to change the process title.</comment>');
}
}

// force the creation of the synopsis before the merge with the app definition
$this->getSynopsis();

Expand Down Expand Up @@ -411,6 +422,25 @@ public function setName($name)
return $this;
}

/**
* Sets the process name of the command.
*
* This feature should be used only when creating a long process command,
* like a daemon.
*
* PHP 5.5+ or the proctitle PECL library is required
*
* @param string $name The process name
*
* @return Command The current instance
*/
public function setProcessName($name)
Copy link
Contributor

Choose a reason for hiding this comment

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

why is it called process name when the underlying methods name it process title?

Copy link
Member Author

Choose a reason for hiding this comment

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

Good point. This could be change before the release of Symfony 2.5. I will open a PR.

Copy link
Member Author

Choose a reason for hiding this comment

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

see #10474

{
$this->processName = $name;

return $this;
}

/**
* Returns the command name.
*
Expand Down