Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

[Console] Added a way to set the process title

  • Loading branch information...
commit 56d10150d0c1f1c20511b1826a2a3c40e87f6d3e 1 parent ff8d544
@lyrixx lyrixx authored
Showing with 35 additions and 0 deletions.
  1. +5 −0 CHANGELOG.md
  2. +30 −0 Command/Command.php
View
5 CHANGELOG.md
@@ -1,6 +1,11 @@
CHANGELOG
=========
+2.5.0
+-----
+
+* added a way to set the process name of a command
+
2.4.0
-----
View
30 Command/Command.php
@@ -33,6 +33,7 @@ class Command
{
private $application;
private $name;
+ private $processName;
private $aliases = array();
private $definition;
private $help;
@@ -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);
+ } 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();
@@ -412,6 +423,25 @@ public function setName($name)
}
/**
+ * 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)
+ {
+ $this->processName = $name;
+
+ return $this;
+ }
+
+ /**
* Returns the command name.
*
* @return string The command name
Please sign in to comment.
Something went wrong with that request. Please try again.