文字

setproctitle

(PECL proctitle >= 0.1.0)

setproctitleSet the process title

说明

void setproctitle ( string $title )

Sets the process title of the current process.

参数

title

The title to use as the process title.

返回值

没有返回值。

范例

Example #1 setproctitle() example

Running the example below will change the process title (visible with ps a for example).

<?php
setproctitle
( "myscript" );
?>

以上例程的输出类似于:

$ ps a
  PID TTY      STAT   TIME COMMAND
 1168 pts/3    S      0:00 myscript                                                                                                                         

参见

  • cli_set_process_title() - Sets the process title
  • pcntl_fork() - 在当前进程当前位置产生分支(子进程)。译注:fork是创建了一个子进程,父进程和子进程 都从fork的位置开始向下继续执行,不同的是父进程执行过程中,得到的fork返回值为子进程 号,而子进程得到的是0。
  • setthreadtitle() - Set the thread title

用户评论:

[#1] james at ifixit dot com [2014-03-28 22:12:39]

You should use cli_set_process_title() ( http://php.net/manual/en/function.cli-set-process-title.php ) instead; it's less dangerous and less buggy, and part of PHP itself as of 5.5.

[#2] zodbd421 at gmail dot com [2013-04-21 05:16:02]

Note that this extension is considered buggy.  See https://wiki.php.net/rfc/cli_process_title, which says:

"...but it is incomplete and might lead to memory corruption on Linux (or any OS which does not support setproctitle.

The reason is the extension only has access to original argv[0] (that comes from main()). argv and environ(7) are in contiguous memory space on Linux. The extension presumes that argv[0] can accomodate 128 characters, but usually that is not possible because argv[0] is ??php??. When this happens, the extension will scribble on argv[1], argv[2], etc., and maybe even environ and this can have destructive side effects on the running program."

上一篇: 下一篇: