Automattic / Automattic/prefork
Further possible performance optimization
- Dominant language
- PHP
- Stars
- 89
- Forks
- 7
- PR merge metrics
- No merged PRs in 30d
Description
When the fork()ed 'intern' process exit()s then PHP processes all the __destruct() functions and releases all memory that it allocated for all functions, classes, and variables, etc. This all takes more time that you'd think. _If_ you don't care about all this activity then calling C's exit() makes the fork()ed 'intern' process exit much quicker. Because PHP does not have such a 'raw' exit function then the following patch adds the function pcntl_exit() which is just a thin wrapper around C's exit(). In a simple test fork()ing a 20 MB "hello world" PHP process -- but one which includes a few hundred PHP classes which are loaded and do nothing -- then performance was quadrupled when using the pcntl_exit() instead of exit() :-)
```
diff -Npru php-5.6.6.orig/ext/pcntl/pcntl.c php-5.6.6/ext/pcntl/pcntl.c
--- php-5.6.6.orig/ext/pcntl/pcntl.c 2015-03-20 11:30:59.061195366 -0700
+++ php-5.6.6/ext/pcntl/pcntl.c 2015-03-20 11:35:17.766536667 -0700
@@ -144,6 +144,7 @@ ZEND_END_ARG_INFO()
const zend_function_entry pcntl_functions[] = {
PHP_FE(pcntl_fork, arginfo_pcntl_void)
+ PHP_FE(pcntl_exit, arginfo_pcntl_void)
PHP_FE(pcntl_waitpid, arginfo_pcntl_waitpid)
PHP_FE(pcntl_wait, arginfo_pcntl_wait)
PHP_FE(pcntl_signal, arginfo_pcntl_signal)
@@ -552,6 +553,14 @@ PHP_FUNCTION(pcntl_fork)
}
/* }}} */
+/* {{{ proto int pcntl_exit(void)
+ * Exits the currently running process following the same behavior as the UNIX exit() system call*/
+PHP_FUNCTION(pcntl_exit)
+{
+ exit(0);
+}
+/* }}} */
+
/* {{{ proto int pcntl_alarm(int seconds)
Set an alarm clock for delivery of a signal*/
PHP_FUNCTION(pcntl_alarm)
diff -Npru php-5.6.6.orig/ext/pcntl/php_pcntl.h php-5.6.6/ext/pcntl/php_pcntl.h
--- php-5.6.6.orig/ext/pcntl/php_pcntl.h 2015-03-20 11:30:59.061195366 -0700
+++ php-5.6.6/ext/pcntl/php_pcntl.h 2015-03-20 11:33:33.403895752 -0700
@@ -32,6 +32,7 @@ PHP_MINFO_FUNCTION(pcntl);
PHP_FUNCTION(pcntl_alarm);
PHP_FUNCTION(pcntl_fork);
+PHP_FUNCTION(pcntl_exit);
PHP_FUNCTION(pcntl_waitpid);
PHP_FUNCTION(pcntl_wait);
PHP_FUNCTION(pcntl_wifexited);
diff -Npru php-5.6.6.orig/sapi/cli/php_cli.c php-5.6.6/sapi/cli/php_cli.c
--- php-5.6.6.orig/sapi/cli/php_cli.c 2015-03-20 11:30:59.478245242 -0700
+++ php-5.6.6/sapi/cli/php_cli.c 2015-03-20 11:31:39.829102985 -0700
@@ -457,7 +457,7 @@ static sapi_module_struct cli_sapi_modul
php_error, /* error handler */
- sapi_cli_header_handler, /* header handler */
+ NULL, /* header handler */
sapi_cli_send_headers, /* send headers handler */
sapi_cli_send_header, /* send header handler */
```
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.