@@ -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