Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 204a25e

Browse filesBrowse files
committed
[Console] Added a way to set the process title
1 parent 67ae8fa commit 204a25e
Copy full SHA for 204a25e

File tree

Expand file treeCollapse file tree

2 files changed

+35
-0
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+35
-0
lines changed

‎src/Symfony/Component/Console/CHANGELOG.md

Copy file name to clipboardExpand all lines: src/Symfony/Component/Console/CHANGELOG.md
+5Lines 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

Copy file name to clipboardExpand all lines: src/Symfony/Component/Console/Command/Command.php
+30Lines 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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.