Skip to content

Commit 0604220

Browse files
committed
feature #9780 [Console] Added a way to set the process title (lyrixx)
This PR was merged into the 2.5-dev branch. Discussion ---------- [Console] Added a way to set the process title | Q | A | ------------- | --- | Bug fix? | no | New feature? | yes | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | - | License | MIT * I did not write test, because I want to RFC the idea before * Do we want the process update its name when a sub command is executed by a master command ? Commits ------- 204a25e [Console] Added a way to set the process title
2 parents 375a2c7 + 204a25e commit 0604220

File tree

2 files changed

+35
-0
lines changed

2 files changed

+35
-0
lines changed

src/Symfony/Component/Console/CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
CHANGELOG
22
=========
33

4+
2.5.0
5+
-----
6+
7+
* added a way to set the process name of a command
8+
49
2.4.0
510
-----
611

src/Symfony/Component/Console/Command/Command.php

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ class Command
3333
{
3434
private $application;
3535
private $name;
36+
private $processName;
3637
private $aliases = array();
3738
private $definition;
3839
private $help;
@@ -212,6 +213,16 @@ protected function initialize(InputInterface $input, OutputInterface $output)
212213
*/
213214
public function run(InputInterface $input, OutputInterface $output)
214215
{
216+
if (null !== $this->processName) {
217+
if (function_exists('cli_set_process_title')) {
218+
cli_set_process_title($this->processName);
219+
} elseif (function_exists('setproctitle')) {
220+
setproctitle($this->processName);
221+
} elseif (OutputInterface::VERBOSITY_VERY_VERBOSE === $output->getVerbosity()) {
222+
$output->writeln('<comment>Install the proctitle PECL to be able to change the process title.</comment>');
223+
}
224+
}
225+
215226
// force the creation of the synopsis before the merge with the app definition
216227
$this->getSynopsis();
217228

@@ -411,6 +422,25 @@ public function setName($name)
411422
return $this;
412423
}
413424

425+
/**
426+
* Sets the process name of the command.
427+
*
428+
* This feature should be used only when creating a long process command,
429+
* like a daemon.
430+
*
431+
* PHP 5.5+ or the proctitle PECL library is required
432+
*
433+
* @param string $name The process name
434+
*
435+
* @return Command The current instance
436+
*/
437+
public function setProcessName($name)
438+
{
439+
$this->processName = $name;
440+
441+
return $this;
442+
}
443+
414444
/**
415445
* Returns the command name.
416446
*

0 commit comments

Comments
 (0)