@@ -710,42 +710,47 @@ static int sapi_cgi_activate(TSRMLS_D)
710
710
return FAILURE ;
711
711
}
712
712
713
- doc_root = sapi_cgibin_getenv ("DOCUMENT_ROOT" , sizeof ("DOCUMENT_ROOT" ) - 1 TSRMLS_CC );
714
- server_name = sapi_cgibin_getenv ("SERVER_NAME" , sizeof ("SERVER_NAME" ) - 1 TSRMLS_CC );
715
-
716
- /* DOCUMENT_ROOT and SERVER_NAME should also be defined at this stage..but better check it anyway */
717
- if (!doc_root || !server_name ) {
718
- return FAILURE ;
719
- }
720
- doc_root_len = strlen (doc_root );
721
- if (doc_root [doc_root_len - 1 ] == '/' ) {
722
- -- doc_root_len ;
723
- }
724
-
725
- /* Prepare search path */
726
- path_len = strlen (SG (request_info ).path_translated );
727
- path = zend_strndup (SG (request_info ).path_translated , path_len );
728
- php_dirname (path , path_len );
729
- path_len = strlen (path );
730
-
731
- /* Make sure we have trailing slash! */
732
- if (!IS_SLASH (path [path_len ])) {
733
- path [path_len ++ ] = DEFAULT_SLASH ;
713
+ if (php_ini_has_per_host_config ()) {
714
+ /* Activate per-host-system-configuration defined in php.ini and stored into configuration_hash during startup */
715
+ server_name = sapi_cgibin_getenv ("SERVER_NAME" , sizeof ("SERVER_NAME" ) - 1 TSRMLS_CC );
716
+ /* SERVER_NAME should also be defined at this stage..but better check it anyway */
717
+ if (server_name ) {
718
+ php_ini_activate_per_host_config (server_name , strlen (server_name ) + 1 TSRMLS_CC );
719
+ }
734
720
}
735
- path [path_len ] = 0 ;
736
721
737
- /* Activate per-dir-system-configuration defined in php.ini and stored into configuration_hash during startup */
738
- php_ini_activate_per_dir_config (path , path_len TSRMLS_CC ); /* Note: for global settings sake we check from root to path */
722
+ if (php_ini_has_per_dir_config () ||
723
+ (PG (user_ini_filename ) && * PG (user_ini_filename ))) {
724
+ /* Prepare search path */
725
+ path_len = strlen (SG (request_info ).path_translated );
726
+ path = estrndup (SG (request_info ).path_translated , path_len );
727
+ path_len = zend_dirname (path , path_len );
739
728
740
- /* Activate per-host-system-configuration defined in php.ini and stored into configuration_hash during startup */
741
- php_ini_activate_per_host_config (server_name , strlen (server_name ) + 1 TSRMLS_CC );
729
+ /* Make sure we have trailing slash! */
730
+ if (!IS_SLASH (path [path_len ])) {
731
+ path [path_len ++ ] = DEFAULT_SLASH ;
732
+ }
733
+ path [path_len ] = 0 ;
734
+
735
+ /* Activate per-dir-system-configuration defined in php.ini and stored into configuration_hash during startup */
736
+ php_ini_activate_per_dir_config (path , path_len TSRMLS_CC ); /* Note: for global settings sake we check from root to path */
737
+
738
+ /* Load and activate user ini files in path starting from DOCUMENT_ROOT */
739
+ if (PG (user_ini_filename ) && * PG (user_ini_filename )) {
740
+ doc_root = sapi_cgibin_getenv ("DOCUMENT_ROOT" , sizeof ("DOCUMENT_ROOT" ) - 1 TSRMLS_CC );
741
+ /* DOCUMENT_ROOT should also be defined at this stage..but better check it anyway */
742
+ if (doc_root ) {
743
+ doc_root_len = strlen (doc_root );
744
+ if (doc_root [doc_root_len - 1 ] == '/' ) {
745
+ -- doc_root_len ;
746
+ }
747
+ php_cgi_ini_activate_user_config (path , path_len , doc_root_len - 1 TSRMLS_CC );
748
+ }
749
+ }
742
750
743
- /* Load and activate user ini files in path starting from DOCUMENT_ROOT */
744
- if (strlen (PG (user_ini_filename ))) {
745
- php_cgi_ini_activate_user_config (path , path_len , doc_root_len - 1 TSRMLS_CC );
751
+ efree (path );
746
752
}
747
753
748
- free (path );
749
754
return SUCCESS ;
750
755
}
751
756
0 commit comments