Skip to content

[Console] Added ability to set the process title #10471

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from

Conversation

florianv
Copy link
Contributor

Q A
Bug fix? no
New feature? yes
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets
License MIT
Doc PR

As of PHP 5.5 it's possible to set CLI processes titles.

Output of the ps command. Before:
before

After:
after

@stof
Copy link
Member

stof commented Mar 17, 2014

How does it behave with #9780 ?

@stof
Copy link
Member

stof commented Mar 17, 2014

btw, the previous implementation used the PECL extension as a fallback. This should be consistent here

@fabpot
Copy link
Member

fabpot commented Mar 17, 2014

Looks like the same as #9780 (which has already been merged) without the fallback.

@stof
Copy link
Member

stof commented Mar 17, 2014

not exactly. #9780 sets a process title configured by the command, or nothing when not configured. This one sets a default one (which is then overwritten by the command one hopefully to maintain the feature).

However, I think a better implementation would be to modify the Command process name handling to set the default title when it does not have a custom one

@florianv
Copy link
Contributor Author

Sorry, I didn't see it was implemented already.

Indeed this PR sets a value by default using the template %app% - %cmd% which would give for example Symfony - doctrine:schema:update.

The advantage I see in putting the handling in the application is the ability to have two different titles for two different applications (with different names) using the same commands without having to set a different title for each command.

However this implementation does not have the fallback as @fabpot mentionned.

@florianv
Copy link
Contributor Author

I can propose this alternative commit to merge both changes florianv@8b3e3e7

  • sets a title by default if the functions are supported
  • allows to customize the process title with placeholders

@fabpot
Copy link
Member

fabpot commented Mar 17, 2014

Looks good to me (/cc @lyrixx)

@lyrixx
Copy link
Member

lyrixx commented Mar 17, 2014

I'm not sure it's really needed to change the title of command like doctrine:generate:entity.
IMHO, the process title should be changed only when it's a long process, like consumers.

More over, you dropped the fallback to the PECL. And in your last commit, you dropped the notice when none of the two functions exists.

Then the default command title contains space. This is not useful when "grepping". On my computer, none process has a title with a space. I think there is a reason for that.

So I'm -1 with this feature.

@florianv
Copy link
Contributor Author

I think it's nice to have a default value working out of the box for framework users. So if they add a command to their bundle, for example to use in a cron job, it will have a nice title by default without having to call setProcessName. That's why the notice has been dropped.

Considering the usage in grep, I can remove the spaces. But it won't be hard to use because the pattern is known ps -A | grep Symfony - namespace:sleep.
It's also possible to grep easily all Symfony framework processes running ps -A | grep Symfony.

@stof
Copy link
Member

stof commented Mar 18, 2014

@florianv the notice should be kept if they set a custom process title and we are not able to apply it

@fabpot
Copy link
Member

fabpot commented Mar 18, 2014

I'm -1 on this change. Setting the process title should be opt-in.

@florianv
Copy link
Contributor Author

I understand the point of not doing too much magic and at the same time it seems easy to set the title with the current handling but I think it will need to be documented after #10474 is merged.
So I close this PR as the placeholders are not needed because we can easily get the application name from the command.

@florianv florianv closed this Mar 18, 2014
@lyrixx
Copy link
Member

lyrixx commented Mar 18, 2014

@florianv For your information, you can easily do this on your side, with command events.

@florianv
Copy link
Contributor Author

@lyrixx thanks. Maybe simpler in initialize(), for example:

$this->setProcessTitle($this->application->getName().'-'.$this->name);

@stof
Copy link
Member

stof commented Mar 18, 2014

@florianv this would work only for your own commands (so not equivalent to your proposal here). The event allows doing it for all commands

@florianv
Copy link
Contributor Author

@stof yes while allowing to keep the default title for some commands which is not possible with this PR.

@florianv florianv deleted the process-title branch March 26, 2014 20:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants