mirror of
https://github.com/php/php-src.git
synced 2024-09-21 18:07:23 +00:00
Optimized request startup sequence for php.ini without per dir and per host configurations
This commit is contained in:
parent
8401580c37
commit
ba8e3174ce
@ -50,6 +50,8 @@ typedef struct _php_extension_lists {
|
|||||||
static int is_special_section = 0;
|
static int is_special_section = 0;
|
||||||
static HashTable *active_ini_hash;
|
static HashTable *active_ini_hash;
|
||||||
static HashTable configuration_hash;
|
static HashTable configuration_hash;
|
||||||
|
static int has_per_dir_config = 0;
|
||||||
|
static int has_per_host_config = 0;
|
||||||
PHPAPI char *php_ini_opened_path=NULL;
|
PHPAPI char *php_ini_opened_path=NULL;
|
||||||
static php_extension_lists extension_lists;
|
static php_extension_lists extension_lists;
|
||||||
PHPAPI char *php_ini_scanned_files=NULL;
|
PHPAPI char *php_ini_scanned_files=NULL;
|
||||||
@ -264,6 +266,7 @@ static void php_ini_parser_cb(zval *arg1, zval *arg2, zval *arg3, int callback_t
|
|||||||
key = key + sizeof("PATH") - 1;
|
key = key + sizeof("PATH") - 1;
|
||||||
key_len = Z_STRLEN_P(arg1) - sizeof("PATH") + 1;
|
key_len = Z_STRLEN_P(arg1) - sizeof("PATH") + 1;
|
||||||
is_special_section = 1;
|
is_special_section = 1;
|
||||||
|
has_per_dir_config = 1;
|
||||||
|
|
||||||
/* HOST sections */
|
/* HOST sections */
|
||||||
} else if (!strncasecmp(Z_STRVAL_P(arg1), "HOST", sizeof("HOST") - 1)) {
|
} else if (!strncasecmp(Z_STRVAL_P(arg1), "HOST", sizeof("HOST") - 1)) {
|
||||||
@ -271,6 +274,8 @@ static void php_ini_parser_cb(zval *arg1, zval *arg2, zval *arg3, int callback_t
|
|||||||
key = key + sizeof("HOST") - 1;
|
key = key + sizeof("HOST") - 1;
|
||||||
key_len = Z_STRLEN_P(arg1) - sizeof("HOST") + 1;
|
key_len = Z_STRLEN_P(arg1) - sizeof("HOST") + 1;
|
||||||
is_special_section = 1;
|
is_special_section = 1;
|
||||||
|
has_per_host_config = 1;
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
is_special_section = 0;
|
is_special_section = 0;
|
||||||
}
|
}
|
||||||
@ -737,6 +742,14 @@ PHPAPI void php_ini_activate_config(HashTable *source_hash, int modify_type, int
|
|||||||
}
|
}
|
||||||
/* }}} */
|
/* }}} */
|
||||||
|
|
||||||
|
/* {{{ php_ini_has_per_dir_config
|
||||||
|
*/
|
||||||
|
PHPAPI int php_ini_has_per_dir_config(void)
|
||||||
|
{
|
||||||
|
return has_per_dir_config;
|
||||||
|
}
|
||||||
|
/* }}} */
|
||||||
|
|
||||||
/* {{{ php_ini_activate_per_dir_config
|
/* {{{ php_ini_activate_per_dir_config
|
||||||
*/
|
*/
|
||||||
PHPAPI void php_ini_activate_per_dir_config(char *path, uint path_len TSRMLS_DC)
|
PHPAPI void php_ini_activate_per_dir_config(char *path, uint path_len TSRMLS_DC)
|
||||||
@ -745,7 +758,7 @@ PHPAPI void php_ini_activate_per_dir_config(char *path, uint path_len TSRMLS_DC)
|
|||||||
char *ptr;
|
char *ptr;
|
||||||
|
|
||||||
/* Walk through each directory in path and apply any found per-dir-system-configuration from configuration_hash */
|
/* Walk through each directory in path and apply any found per-dir-system-configuration from configuration_hash */
|
||||||
if (path && path_len) {
|
if (has_per_dir_config && path && path_len) {
|
||||||
ptr = path + 1;
|
ptr = path + 1;
|
||||||
while ((ptr = strchr(ptr, DEFAULT_SLASH)) != NULL) {
|
while ((ptr = strchr(ptr, DEFAULT_SLASH)) != NULL) {
|
||||||
*ptr = 0;
|
*ptr = 0;
|
||||||
@ -760,13 +773,21 @@ PHPAPI void php_ini_activate_per_dir_config(char *path, uint path_len TSRMLS_DC)
|
|||||||
}
|
}
|
||||||
/* }}} */
|
/* }}} */
|
||||||
|
|
||||||
|
/* {{{ php_ini_has_per_host_config
|
||||||
|
*/
|
||||||
|
PHPAPI int php_ini_has_per_host_config(void)
|
||||||
|
{
|
||||||
|
return has_per_host_config;
|
||||||
|
}
|
||||||
|
/* }}} */
|
||||||
|
|
||||||
/* {{{ php_ini_activate_per_host_config
|
/* {{{ php_ini_activate_per_host_config
|
||||||
*/
|
*/
|
||||||
PHPAPI void php_ini_activate_per_host_config(char *host, uint host_len TSRMLS_DC)
|
PHPAPI void php_ini_activate_per_host_config(char *host, uint host_len TSRMLS_DC)
|
||||||
{
|
{
|
||||||
zval *tmp;
|
zval *tmp;
|
||||||
|
|
||||||
if (host && host_len) {
|
if (has_per_host_config && host && host_len) {
|
||||||
/* Search for source array matching the host from configuration_hash */
|
/* Search for source array matching the host from configuration_hash */
|
||||||
if (zend_hash_find(&configuration_hash, host, host_len, (void **) &tmp) == SUCCESS) {
|
if (zend_hash_find(&configuration_hash, host, host_len, (void **) &tmp) == SUCCESS) {
|
||||||
php_ini_activate_config(Z_ARRVAL_P(tmp), PHP_INI_SYSTEM, PHP_INI_STAGE_ACTIVATE TSRMLS_CC);
|
php_ini_activate_config(Z_ARRVAL_P(tmp), PHP_INI_SYSTEM, PHP_INI_STAGE_ACTIVATE TSRMLS_CC);
|
||||||
|
@ -34,6 +34,8 @@ PHPAPI int cfg_get_double(char *varname, double *result);
|
|||||||
PHPAPI int cfg_get_string(char *varname, char **result);
|
PHPAPI int cfg_get_string(char *varname, char **result);
|
||||||
PHPAPI int php_parse_user_ini_file(char *dirname, char *ini_filename, HashTable *target_hash TSRMLS_DC);
|
PHPAPI int php_parse_user_ini_file(char *dirname, char *ini_filename, HashTable *target_hash TSRMLS_DC);
|
||||||
PHPAPI void php_ini_activate_config(HashTable *source_hash, int modify_type, int stage TSRMLS_DC);
|
PHPAPI void php_ini_activate_config(HashTable *source_hash, int modify_type, int stage TSRMLS_DC);
|
||||||
|
PHPAPI int php_ini_has_per_dir_config(void);
|
||||||
|
PHPAPI int php_ini_has_per_host_config(void);
|
||||||
PHPAPI void php_ini_activate_per_dir_config(char *path, uint path_len TSRMLS_DC);
|
PHPAPI void php_ini_activate_per_dir_config(char *path, uint path_len TSRMLS_DC);
|
||||||
PHPAPI void php_ini_activate_per_host_config(char *host, uint host_len TSRMLS_DC);
|
PHPAPI void php_ini_activate_per_host_config(char *host, uint host_len TSRMLS_DC);
|
||||||
PHPAPI HashTable* php_ini_get_configuration_hash(void);
|
PHPAPI HashTable* php_ini_get_configuration_hash(void);
|
||||||
|
@ -710,23 +710,21 @@ static int sapi_cgi_activate(TSRMLS_D)
|
|||||||
return FAILURE;
|
return FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
doc_root = sapi_cgibin_getenv("DOCUMENT_ROOT", sizeof("DOCUMENT_ROOT") - 1 TSRMLS_CC);
|
if (php_ini_has_per_host_config()) {
|
||||||
|
/* Activate per-host-system-configuration defined in php.ini and stored into configuration_hash during startup */
|
||||||
server_name = sapi_cgibin_getenv("SERVER_NAME", sizeof("SERVER_NAME") - 1 TSRMLS_CC);
|
server_name = sapi_cgibin_getenv("SERVER_NAME", sizeof("SERVER_NAME") - 1 TSRMLS_CC);
|
||||||
|
/* SERVER_NAME should also be defined at this stage..but better check it anyway */
|
||||||
/* DOCUMENT_ROOT and SERVER_NAME should also be defined at this stage..but better check it anyway */
|
if (server_name) {
|
||||||
if (!doc_root || !server_name) {
|
php_ini_activate_per_host_config(server_name, strlen(server_name) + 1 TSRMLS_CC);
|
||||||
return FAILURE;
|
|
||||||
}
|
}
|
||||||
doc_root_len = strlen(doc_root);
|
|
||||||
if (doc_root[doc_root_len - 1] == '/') {
|
|
||||||
--doc_root_len;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (php_ini_has_per_dir_config() ||
|
||||||
|
(PG(user_ini_filename) && *PG(user_ini_filename))) {
|
||||||
/* Prepare search path */
|
/* Prepare search path */
|
||||||
path_len = strlen(SG(request_info).path_translated);
|
path_len = strlen(SG(request_info).path_translated);
|
||||||
path = zend_strndup(SG(request_info).path_translated, path_len);
|
path = estrndup(SG(request_info).path_translated, path_len);
|
||||||
php_dirname(path, path_len);
|
path_len = zend_dirname(path, path_len);
|
||||||
path_len = strlen(path);
|
|
||||||
|
|
||||||
/* Make sure we have trailing slash! */
|
/* Make sure we have trailing slash! */
|
||||||
if (!IS_SLASH(path[path_len])) {
|
if (!IS_SLASH(path[path_len])) {
|
||||||
@ -737,15 +735,22 @@ static int sapi_cgi_activate(TSRMLS_D)
|
|||||||
/* Activate per-dir-system-configuration defined in php.ini and stored into configuration_hash during startup */
|
/* Activate per-dir-system-configuration defined in php.ini and stored into configuration_hash during startup */
|
||||||
php_ini_activate_per_dir_config(path, path_len TSRMLS_CC); /* Note: for global settings sake we check from root to path */
|
php_ini_activate_per_dir_config(path, path_len TSRMLS_CC); /* Note: for global settings sake we check from root to path */
|
||||||
|
|
||||||
/* Activate per-host-system-configuration defined in php.ini and stored into configuration_hash during startup */
|
|
||||||
php_ini_activate_per_host_config(server_name, strlen(server_name) + 1 TSRMLS_CC);
|
|
||||||
|
|
||||||
/* Load and activate user ini files in path starting from DOCUMENT_ROOT */
|
/* Load and activate user ini files in path starting from DOCUMENT_ROOT */
|
||||||
if (strlen(PG(user_ini_filename))) {
|
if (PG(user_ini_filename) && *PG(user_ini_filename)) {
|
||||||
|
doc_root = sapi_cgibin_getenv("DOCUMENT_ROOT", sizeof("DOCUMENT_ROOT") - 1 TSRMLS_CC);
|
||||||
|
/* DOCUMENT_ROOT should also be defined at this stage..but better check it anyway */
|
||||||
|
if (doc_root) {
|
||||||
|
doc_root_len = strlen(doc_root);
|
||||||
|
if (doc_root[doc_root_len - 1] == '/') {
|
||||||
|
--doc_root_len;
|
||||||
|
}
|
||||||
php_cgi_ini_activate_user_config(path, path_len, doc_root_len - 1 TSRMLS_CC);
|
php_cgi_ini_activate_user_config(path, path_len, doc_root_len - 1 TSRMLS_CC);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
efree(path);
|
||||||
|
}
|
||||||
|
|
||||||
free(path);
|
|
||||||
return SUCCESS;
|
return SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user