1 to test which is main php.ini:
2 $ php -r 'var_dump(array(get_cfg_var("cfg_file_path"),php_ini_loaded_file()));'
4 https://github.com/pld-linux/php/commit/762ec2e
6 --- php-7.0.0RC6.orig/main/php_ini.c 2015-11-10 23:58:52.227101032 +0200
7 +++ php-7.0.0RC6/main/php_ini.c 2015-11-11 00:01:43.502674750 +0200
12 +static int php_csort(const struct dirent **a, const struct dirent **b)
14 + return strcmp((*a)->d_name,(*b)->d_name);
17 /* {{{ php_init_config
19 int php_init_config(void)
21 char *php_ini_file_name = NULL;
22 char *php_ini_search_path = NULL;
23 + // value for php_ini_loaded_file() to be stored into php_ini_opened_path
24 + char *php_ini_loaded_file = NULL;
25 int php_ini_scanned_path_len;
27 int free_ini_search_path = 0;
32 + /* Search (global) php.ini file in search path */
33 + if (!fh.handle.fp) {
34 + fh.handle.fp = php_fopen_with_path("php.ini", "r", php_ini_search_path, &opened_path);
36 + fh.filename = ZSTR_VAL(opened_path);
38 + // parse the ini file now
39 + PG(open_basedir) = open_basedir;
40 + fh.type = ZEND_HANDLE_FP;
41 + zend_parse_ini_file(&fh, 1, ZEND_INI_SCANNER_NORMAL, (zend_ini_parser_cb_t) php_ini_parser_cb, &configuration_hash TSRMLS_CC);
42 + open_basedir = PG(open_basedir);
43 + PG(open_basedir) = NULL;
44 + fh.handle.fp = NULL;
46 + php_ini_loaded_file = estrdup(fh.filename);
51 - /* Otherwise search for php-%sapi-module-name%.ini file in search path */
52 + /* Also search for php-%sapi-module-name%.ini file in search path */
54 const char *fmt = "php-%s.ini";
58 fh.filename = ZSTR_VAL(opened_path);
62 - /* If still no ini file found, search for php.ini file in search path */
63 - if (!fh.handle.fp) {
64 - fh.handle.fp = php_fopen_with_path("php.ini", "r", php_ini_search_path, &opened_path);
66 - fh.filename = ZSTR_VAL(opened_path);
72 if (free_ini_search_path) {
77 + // use main php.ini if loaded
78 + // see https://github.com/pld-linux/php/commit/762ec2e
80 + // php -r 'var_dump(array(get_cfg_var("cfg_file_path"),php_ini_loaded_file()));'
81 + if (php_ini_loaded_file) {
83 + efree((char *)fh.filename);
85 + fh.filename = php_ini_loaded_file;
88 ZVAL_NEW_STR(&tmp, zend_string_init(fh.filename, strlen(fh.filename), 1));
89 zend_hash_str_update(&configuration_hash, "cfg_file_path", sizeof("cfg_file_path")-1, &tmp);
91 zend_string_release(opened_path);
96 efree((char *)fh.filename);
100 php_ini_opened_path = zend_strndup(Z_STRVAL(tmp), Z_STRLEN(tmp));
103 @@ -624,13 +656,15 @@
104 zend_llist scanned_ini_list;
105 zend_llist_element *element;
107 + const char *fmt = "%s:" PHP_CONFIG_FILE_PATH "/%s.d";
108 char *bufpath, *debpath, *endpath;
111 zend_llist_init(&scanned_ini_list, sizeof(char *), (llist_dtor_func_t) free_estring, 1);
112 memset(&fh2, 0, sizeof(fh2));
114 - bufpath = estrdup(php_ini_scanned_path);
115 + bufpath = emalloc(strlen(php_ini_scanned_path) + strlen(fmt) + strlen(sapi_module.name));
116 + sprintf(bufpath, fmt, php_ini_scanned_path, sapi_module.name);
117 for (debpath = bufpath ; debpath ; debpath=endpath) {
118 endpath = strchr(debpath, DEFAULT_DIR_SEPARATOR);
122 lenpath = (int)strlen(debpath);
124 - if (lenpath > 0 && (ndir = php_scandir(debpath, &namelist, 0, php_alphasort)) > 0) {
125 + if (lenpath > 0 && (ndir = php_scandir(debpath, &namelist, 0, php_csort)) > 0) {
127 for (i = 0; i < ndir; i++) {