php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #34570 Implement some sort of setproctitle() in cli version
Submitted: 2005-09-20 23:39 UTC Modified: 2011-04-28 13:05 UTC
Votes:8
Avg. Score:5.0 ± 0.0
Reproduced:8 of 8 (100.0%)
Same Version:4 (50.0%)
Same OS:5 (62.5%)
From: steve-php-dev at spwiz dot com Assigned: bjori (profile)
Status: Closed Package: *General Issues
PHP Version: 5.0.5 OS: Linux 2.4 kernel
Private report: No CVE-ID: None
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: steve-php-dev at spwiz dot com
New email:
PHP Version: OS:

 

 [2005-09-20 23:39 UTC] steve-php-dev at spwiz dot com
Description:
------------
I'm using the pcntl module in the CLI SAPI to fork off several processes.  I'd like the processes to be able to identify themselves in ps.  In Linux, you can do this by editing argv[0].  On BSD, you use the setproctitle() function.  Other higher level languages support this feature.  A simple perl script to do this on Linux would be:

$0 = "bogus";
sleep 10;

I tried modifying $argv[0], but that only modified the PHP scripts copy of argv, not the real argv.  It'd be nice if there was a way to modify the process title directly.  Ideally, it would be cross-platform (for Unix variants, at least).

This was originally requested in 2002 (http://bugs.php.net/bug.php?id=18400), but was rejected.  When using the pcntl functions in the CLI version, it really would be a useful feature.


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2011-01-23 01:48 UTC] matt at mralston dot co dot uk
I can't stress how much I'd like to see this feature implemented.

I'm not a C programmer and I haven't got a clue how PHP is structured behind the 
scenes, but I can't 
imagine that this feature would be difficult to implement.

I've been through a quite a journey with this conundrum today. I started out 
coding a new daemon 
this morning. Began to wish I could change the "/usr/bin/php ./caiman.php start" 
entry in the "ps 
auxw" listing this afternoon. I then spent some time researching how to do it 
(which was fustrating 
because I didn't even know how to phrase the question for Google when I 
started). I eventually found 
some C++ forums talking about modifying argv[0] and was excited and then 
disappointed when I found it 
didn't work in PHP. I drafted out a long e-mail I intended to send to the PHP 
developers, then figured 
I'd better properly RTFM and check out the bug tracker first. That's when I came 
across this feature request 
(and an older one from 2002). Unfortunately both appear to have stalled.

So here I am, adding my voice to this request. I can grovel if you like!

Please, please, please would somebody have a go at adding this feature when 
they've got some spare 
time? Even if the feature is ultimately rejected for inclusion into the trunk, a 
little patch that I 
could apply to my own servers would be appreciated so much.

In the meantime, I'm just about to start poking around the PHP sources on my 
development box and see 
if I can implement something myself. As I said, I'm not a C programmer so I 
expect to struggle, but 
it's worth a shot. I'm thinking of something like:

void pcntl_setproctitle(char *new_title)
{
	sprintf(argv[0], new_title);
}

Thanks for listening to me ramble.

- Matt
 [2011-01-23 08:03 UTC] dtajchreber@php.net
-Package: Feature/Change Request +Package: *General Issues
 [2011-01-23 12:59 UTC] matt at mralston dot co dot uk
Fantastic!

In the dictionary, there's an entry for "short and sweet", and next to it is your post!

Thank you very much. And thank you PECL. And thank you Wikipedia!

I've never given PECL much attention before; I now see the error of my ways.


USER       PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
daemon    7269  0.0  0.0 124696  3500 ?        Ss   11:59   0:00 [CAIMan]


I'm a happy bunny! Thank you.
 [2011-04-28 13:05 UTC] bjori@php.net
-Status: Open +Status: Closed -Assigned To: +Assigned To: bjori
 [2011-04-28 13:05 UTC] bjori@php.net
Already exists in pecl. See also http://php.net/setproctitle
closing
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Sun Jul 06 19:01:36 2025 UTC