rfc:cli_process_title
no way to compare when less than two revisions
Differences
This shows you the differences between two versions of the page.
Previous revisionNext revision | |||
— | rfc:cli_process_title [2013/02/08 20:39] – Move to voting keyur | ||
---|---|---|---|
Line 1: | Line 1: | ||
+ | ====== Request for Comments: PHP CLI changing process title support ====== | ||
+ | * Version: 1.1 | ||
+ | * Date: 2013-02-06 | ||
+ | * Author: Keyur Govande < | ||
+ | * Status: Voting | ||
+ | * First Published at: http:// | ||
+ | |||
+ | ===== Introduction ===== | ||
+ | |||
+ | This RFC proposes a new way of setting a PHP CLI process' | ||
+ | |||
+ | This is very helpful when using PHP as a daemon, for example: [[https:// | ||
+ | |||
+ | '' | ||
+ | |||
+ | Currently, there are 2 ways to debug what job a process is doing: attach gdb and introspect the appropriate data structure. Or log the process-pid to a file at job start-up and match it up. | ||
+ | |||
+ | Both are doable, but time consuming and having functionality in the language to set the title would solve the problem nicely. | ||
+ | ===== Implementation ===== | ||
+ | |||
+ | There already exists a PECL extension [[http:// | ||
+ | |||
+ | 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 " | ||
+ | |||
+ | The proposed patch does not suffer from the same issue. It works by hooking into PHP CLI's main(). An init method is the first function call made in main(). | ||
+ | * On Linux: The init method deep-copies argv and environ and these copies are returned to main() for use during the program. The original argv and environ are saved by init. This contiguous block is then used to store the the new title. The OS reads from argv[0] onwards when ps(1) or top(1) or / | ||
+ | * On BSD without [[http:// | ||
+ | * On systems with support for [[http:// | ||
+ | * On Windows: the title is set as an Windows [[http:// | ||
+ | |||
+ | Support for setting the title is also built into the cli-server SAPI. | ||
+ | |||
+ | Note that it is not possible to use similar logic for other web-servers like Apache because we'd need to deep-copy and replace argv and environ before any real code has executed and such low-level access isn't possible there. | ||
+ | ==== Example ==== | ||
+ | |||
+ | <code php> | ||
+ | <?php | ||
+ | |||
+ | $title = "This is a test title"; | ||
+ | if (!cli_set_process_title($title)) { | ||
+ | echo " | ||
+ | exit(1); | ||
+ | } | ||
+ | |||
+ | sleep(15); | ||
+ | </ | ||
+ | |||
+ | The above example will output: | ||
+ | |||
+ | * Linux: {{: | ||
+ | * FreeBSD 9.0: {{: | ||
+ | * Windows 7: {{: | ||
+ | * OS X Lion: {{: | ||
+ | |||
+ | ===== Patch ===== | ||
+ | |||
+ | The patch (including tests) based off of 5.4.11 is [[https:// | ||
+ | |||
+ | ===== Voting ===== | ||
+ | |||
+ | The PHP language is not changed, so a 50% + 1 majority is required. | ||
+ | |||
+ | <doodle title=" | ||
+ | * Yes | ||
+ | * No | ||
+ | </ | ||
+ | |||
+ | ===== Changelog ===== | ||
+ | |||
+ | * 1.0 (2012-02-06): | ||
+ | * 1.1 (2012-02-07): |
rfc/cli_process_title.txt · Last modified: 2017/09/22 13:28 by 127.0.0.1