Ingwie Phoenix
Ingwie Phoenix

Reputation: 2983

Giving a PHP CLI process a process name

For a project I am working on, I am spawning a multiple amount of worker processes. Thing is, they don't appear in Apple's Activity Monitor, because they don't have a proper title set.

I tried to use the cli_set_process_title function that is available since PHP 5.5. Unfortunately, this is what XDebug pins me to the console:

Warning: cli_set_process_title(): cli_set_process_title had an error: Not initialized correctly in /Users/Ingwie/Work/BIRD3/php-lib/yii_worker.php on line 22

Call Stack:
    0.0012     264080   1. {main}() /Users/Ingwie/Work/BIRD3/php-lib/request_handler.php:0
    0.0286    1219016   2. Workerman\Worker::runAll() /Users/Ingwie/Work/BIRD3/php-lib2015-07-01T20:12:03.185Z - info: BIRD3 worker@41603 is online!
/request_handler.php:103
    0.0315    1252488   3. Workerman\Worker::forkWorkers() /Users/Ingwie/Work/BIRD3/php_modules/walkor/workerman/Worker.php:328
    0.0507    1254312   4. Workerman\Worker::forkOneWorker() /Users/Ingwie/Work/BIRD3/php_modules/walkor/workerman/Worker.php:748
    0.0561    1252896   5. Workerman\Hprose->run() /Users/Ingwie/Work/BIRD3/php_modules/walkor/workerman/Worker.php:779
    0.0561    1253744   6. Workerman\Worker->run() /Users/Ingwie/Work/BIRD3/php_modules_ext/hprose-workerman/HproseWorkermanService.php:142
    0.0591    1316400   7. call_user_func() /Users/Ingwie/Work/BIRD3/php_modules/walkor/workerman/Worker.php:1286
    0.0591    1316472   8. AppServer::{closure:/Users/Ingwie/Work/BIRD3/php-lib/request_handler.php:38-40}() /Users/Ingwie/Work/BIRD3/php_modules/walkor/workerman/Worker.php:1286
    0.0592    1316920   9. AppServer::emit() /Users/Ingwie/Work/BIRD3/php-lib/request_handler.php:39
    0.0592    1318152  10. call_user_func_array() /Users/Ingwie/Work/BIRD3/php-lib/request_handler.php:76
    0.0593    1318224  11. Evenement\EventEmitter->emit() /Users/Ingwie/Work/BIRD3/php-lib/request_handler.php:76
    0.0593    1318320  12. call_user_func_array() /Users/Ingwie/Work/BIRD3/php_modules/evenement/evenement/src/Evenement/EventEmitterTrait.php:64
    0.0593    1318704  13. {closure:/Users/Ingwie/Work/BIRD3/php-lib/yii_worker.php:21-25}() /Users/Ingwie/Work/BIRD3/php_modules/evenement/evenement/src/Evenement/EventEmitterTrait.php:64
    0.0593    1318800  14. cli_set_process_title() /Users/Ingwie/Work/BIRD3/php-lib/yii_worker.php:22

And the proctitle extension sets a very weird title. It does not appear on the Activity Monitor, but in ps:

  504 44278 44261   0 10:44pm ttys000    0:00.00 BIRD3: Workerman Worker                                                                                                         local/etc/fish __fish_runtime_dir=/tmp/fish.Ingwie __fish_help_dir=/usr/local/share/doc/fish __fish_datadir=/usr/local/share/fish __fish_bin_dir=/usr/local/bin

and that isn't even all of my environment variables.

As you can see, there seems to be no way to set a process title.

Or do you know one?

PHP: 5.5.20 OS X: 10.10.3

PHP is OS supplied:

Ingwie@Ingwies-MBP ~/W/BIRD3 $ php-config --configure-options
--prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --disable-dependency-tracking --sysconfdir=/private/etc --with-apxs2=/usr/sbin/apxs --enable-cli --with-config-file-path=/etc --with-config-file-scan-dir=/Library/Server/Web/Config/php --with-libxml-dir=/usr --with-openssl=/usr --with-kerberos=/usr --with-zlib=/usr --enable-bcmath --with-bz2=/usr --enable-calendar --disable-cgi --with-curl=/usr --enable-dba --with-ndbm=/usr --enable-exif --enable-fpm --enable-ftp --with-png-dir=no --with-gd --with-jpeg-dir=/usr/local --enable-gd-native-ttf --with-icu-dir=/usr --with-ldap=/usr --with-ldap-sasl=/usr --with-libedit=/usr --enable-mbstring --enable-mbregex --with-mysql=mysqlnd --with-mysqli=mysqlnd --without-pear --with-pear=no --with-pdo-mysql=mysqlnd --with-mysql-sock=/var/mysql/mysql.sock --with-readline=/usr --enable-shmop --with-snmp=/usr --enable-soap --enable-sockets --enable-sysvmsg --enable-sysvsem --enable-sysvshm --with-tidy --enable-wddx --with-xmlrpc --with-iconv-dir=/usr --with-xsl=/usr --enable-zend-multibyte --enable-zip --with-pcre-regex=/usr

Upvotes: 1

Views: 1198

Answers (1)

dlegall
dlegall

Reputation: 412

It seems to be necessary to be superuser to use this functionnality on MacOS 10.10.x.

Sorry for not able to help you getting this working.

Link to advanced discussion about this problem : Cannot set process title in a PHP command line script using cli_set_process_title() OS X?

Upvotes: 1

Related Questions