@@ -33,6 +33,7 @@ class Command
33
33
{
34
34
private $ application ;
35
35
private $ name ;
36
+ private $ processName ;
36
37
private $ aliases = array ();
37
38
private $ definition ;
38
39
private $ help ;
@@ -212,6 +213,16 @@ protected function initialize(InputInterface $input, OutputInterface $output)
212
213
*/
213
214
public function run (InputInterface $ input , OutputInterface $ output )
214
215
{
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
+
215
226
// force the creation of the synopsis before the merge with the app definition
216
227
$ this ->getSynopsis ();
217
228
@@ -411,6 +422,25 @@ public function setName($name)
411
422
return $ this ;
412
423
}
413
424
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
+
414
444
/**
415
445
* Returns the command name.
416
446
*
0 commit comments