cli_set_process_title
(PHP 5 >= 5.5.0)
cli_set_process_title — Sets the process title
Описание
bool cli_set_process_title
( string
$title
)Sets the process title visible in tools such as top and ps. This function is available only in CLI mode.
Список параметров
-
title
-
The new title.
Возвращаемые значения
Возвращает TRUE
в случае успешного завершения или FALSE
в случае возникновения ошибки.
Ошибки
An E_WARNING
will be generated if the operating system
is unsupported.
Примеры
Пример #1 cli_set_process_title() example
<?php
$title = "My Amazing PHP Script";
$pid = getmypid(); // you can use this to see your process title in ps
if (!cli_set_process_title($title)) {
echo "Unable to set process title for PID $pid...\n";
exit(1);
} else {
echo "The process title '$title' for PID $pid has been set for your process!\n";
sleep(5);
}
?>
- PHP Руководство
- Функции по категориям
- Индекс функций
- Справочник функций
- Изменение поведения PHP
- PHP Опции и Информация
- assert_options
- assert
- cli_get_process_title
- cli_set_process_title
- dl
- extension_loaded
- gc_collect_cycles
- gc_disable
- gc_enable
- gc_enabled
- gc_mem_caches
- get_cfg_var
- get_current_user
- get_defined_constants
- get_extension_funcs
- get_include_path
- get_included_files
- get_loaded_extensions
- get_magic_quotes_gpc
- get_magic_quotes_runtime
- get_required_files
- get_resources
- getenv
- getlastmod
- getmygid
- getmyinode
- getmypid
- getmyuid
- getopt
- getrusage
- ini_alter
- ini_get_all
- ini_get
- ini_restore
- ini_set
- magic_quotes_runtime
- main
- memory_get_peak_usage
- memory_get_usage
- php_ini_loaded_file
- php_ini_scanned_files
- php_logo_guid
- php_sapi_name
- php_uname
- phpcredits
- phpinfo
- phpversion
- putenv
- restore_include_path
- set_include_path
- set_magic_quotes_runtime
- set_time_limit
- sys_get_temp_dir
- version_compare
- zend_logo_guid
- zend_thread_id
- zend_version
Коментарии
Setting proc title on PHP based daemons is pretty sweet.
In Linux this command changes the title for commands like 'ps -a' it doesn't seem to work with 'top' or 'pkill'
To change the short name (eg PHP) to something else you can use the below:
<?php
$strNewName='myscript';
cli_set_process_name($strNewName);
cli_set_process_title($strNewName);
var_dump(cli_get_process_name());
var_dump(cli_get_process_title());
function cli_set_process_name($strName)
{
file_put_contents("/proc/".getmypid()."/comm",$strName);
}
function cli_get_process_name()
{
return(trim(file_get_contents("/proc/".getmypid()."/comm"),"\r\n"));
}
Note: The above will NOT work in Windows and may not work in all flavours of linux (I use Debian).