summaryrefslogtreecommitdiffhomepage
path: root/auto/modules
diff options
context:
space:
mode:
authorTiago Natel de Moura <t.nateldemoura@f5.com>2020-03-03 14:38:08 +0000
committerTiago Natel de Moura <t.nateldemoura@f5.com>2020-03-03 14:38:08 +0000
commitf99d20ad39a62cf30b6b0b01593336572484f4f5 (patch)
treef1db56f1c22d1d1f4a1d6892ce9befdd7cf9ba6a /auto/modules
parent9e295fa3141e8deec7813ea4e0c6fa57d4a87bd8 (diff)
downloadunit-f99d20ad39a62cf30b6b0b01593336572484f4f5.tar.gz
unit-f99d20ad39a62cf30b6b0b01593336572484f4f5.tar.bz2
PHP: optimization to avoid surplus chdir(2) calls.
For each request, the worker calls the php_execute_script function from libphp that changes to the script directory before doing its work and then restores the process directory before returning. The chdir(2) calls it performs are unnecessary in Unit design. In simple benchmarks, profiling shows that the chdir syscall code path (syscall, FS walk, etc.) is where the CPU spends most of its time. PHP SAPI semantics requires the script to be run from the script directory. In Unit's PHP implementation, we have two use cases: - script - arbitrary path The "script" configuration doesn't have much need for a working directory change: it can be changed once at module initialization. The module needs to chdir again only if the user's PHP script also calls chdir to switch to another directory during execution. If "script" is not used in Unit configuration, we must ensure the script is run from its directory (thus calling chdir before exec), but there's no need to restore the working directory later. Our implementation disables mandatory chdir calls with the SAPI option SAPI_OPTION_NO_CHDIR, instead calling chdir only when needed. To detect the user's calls to chdir, a simple "unit" extension is added that hooks the built-in chdir() PHP call.
Diffstat (limited to 'auto/modules')
-rw-r--r--auto/modules/php13
1 files changed, 11 insertions, 2 deletions
diff --git a/auto/modules/php b/auto/modules/php
index 97d1ac43..51b068e7 100644
--- a/auto/modules/php
+++ b/auto/modules/php
@@ -58,6 +58,7 @@ NXT_PHP=${NXT_PHP_CONFIG%-config*}
NXT_PHP_MODULE=${NXT_PHP_MODULE=${NXT_PHP##*/}}
NXT_PHP_LIB_PATH=${NXT_PHP_LIB_PATH=}
NXT_PHP_LIB_STATIC=${NXT_PHP_LIB_STATIC=no}
+NXT_PHP_ADDITIONAL_FLAGS=
$echo "configuring PHP module"
@@ -75,6 +76,14 @@ if /bin/sh -c "${NXT_PHP_CONFIG} --version" >> $NXT_AUTOCONF_ERR 2>&1; then
NXT_PHP_VERSION="`${NXT_PHP_CONFIG} --version`"
$echo " + PHP SAPI: [`${NXT_PHP_CONFIG} --php-sapis`]"
+ NXT_PHP_MAJOR_VERSION=${NXT_PHP_VERSION%%.*}
+ NXT_PHP_MINOR_VERSION=${NXT_PHP_VERSION#??}
+ NXT_PHP_MINOR_VERSION=${NXT_PHP_MINOR_VERSION%.*}
+
+ if [ $NXT_PHP_MAJOR_VERSION = 5 -a $NXT_PHP_MINOR_VERSION -lt 4 ]; then
+ NXT_PHP_ADDITIONAL_FLAGS=-Wno-write-strings
+ fi
+
NXT_PHP_INCLUDE="`${NXT_PHP_CONFIG} --includes`"
if [ $NXT_PHP_LIB_STATIC = yes ]; then
@@ -204,8 +213,8 @@ for nxt_src in $NXT_PHP_MODULE_SRCS; do
cat << END >> $NXT_MAKEFILE
$NXT_BUILD_DIR/$nxt_obj: $nxt_src $NXT_VERSION_H
- \$(CC) -c \$(CFLAGS) \$(NXT_INCS) $NXT_PHP_INCLUDE \\
- -DNXT_ZEND_SIGNAL_STARTUP=$NXT_ZEND_SIGNAL_STARTUP \\
+ \$(CC) -c \$(CFLAGS) $NXT_PHP_ADDITIONAL_FLAGS \$(NXT_INCS) \\
+ $NXT_PHP_INCLUDE -DNXT_ZEND_SIGNAL_STARTUP=$NXT_ZEND_SIGNAL_STARTUP \\
$nxt_dep_flags \\
-o $NXT_BUILD_DIR/$nxt_obj $nxt_src
$nxt_dep_post