|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2004-08-01 10:43 UTC] black at scene-si dot org
Description: ------------ With linux it is sometimes useful to be able to change the process name (by identifying a process in the system error logs or for debugging for example).. The c(++) or the perl way doesnt work in php as far as i tried, and so i pressume that it is not possible itself. You can consult yourself with http://lightconsulting.com/~thalakan/process-title-notes.html - an extensive example of how the title should be changed Reproduce code: --------------- $argv[0] = "progname-debugval"; Expected result: ---------------- I expect that the programs process title would be changed by modifying $argv[0], or by introducing a new function which would change the process title respectively. Actual result: -------------- The process name in `ps` output of the respective program should change accordingly to the change of $argv[0]; PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Wed Oct 29 08:00:01 2025 UTC |
Here is a shorter version based off of xdecock's code which has been working well. I see value in having this available when using PHP in CLI mode. ------------------------------------------- #include <php.h> #include <SAPI.h> #include <dlfcn.h> #include <string.h> static char *argv0 = NULL; #define MAX_TITLE_LENGTH 128 void setproctitle(char *title) { char buffer[MAX_TITLE_LENGTH]; int tlen = strlen(title); memset(buffer, 0x20, MAX_TITLE_LENGTH); buffer[MAX_TITLE_LENGTH-1] = '\0'; if( tlen < (MAX_TITLE_LENGTH-1) ) memcpy(buffer, title, tlen); if( argv0 ) snprintf(argv0, MAX_TITLE_LENGTH, "%s", buffer); } void set_proctitle_init() { sapi_module_struct *symbol = NULL; symbol = (sapi_module_struct *)dlsym(NULL, "sapi_module"); if( symbol ) argv0 = symbol->executable_location; } PHP_FUNCTION(setproctitle) { char *title; long tlen; if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s",&title, &tlen) == FAILURE) RETURN_FALSE; setproctitle(title); }