I've attached the changes that have been requested. The idea is that you can have settings which are from global (not version specific) to the exact PHP version. Including -dev releases.
php [major [.minor [.release [ extra]]]] -sapi.ini or SOFTWARE\\PHP[\\major [.minor [.release [.extra]]]\\ sort of thing. Only 1 ini file is picked up, but with the registry, a setting in \PHP\5\ will be overwritten by a setting in \PHP\5.1\ (assuming it exists) and that by \PHP\5.1.4\ On 30/07/06, Andi Gutmans <[EMAIL PROTECTED]> wrote:
Unless there are objections we can commit it for you. One change I'd like you to make though is to remove the V in the registry before the version #. Makes it harder for automated programs. It should just be SOFTWARE\\PHP\\5\\IniFilePath Btw, one thing I didn't understand. Are you cascading 5 and 5.1 and 5.1.4? That's weird. > -----Original Message----- > From: Richard Quadling [mailto:[EMAIL PROTECTED] > Sent: Sunday, July 30, 2006 6:53 AM > To: internals@lists.php.net > Subject: Re: [PHP-DEV] Supporting version specific INI files > as well as SAPI specific INI files. > > Do I have to do anything else to get this patch submitted? > > Is there anything more required within it? > > Where do I go from here? > > Do I need a sponsor? > > Do I have to get a CVS account with adequate karma to commit > the patch myself? > > Anyone? Is there anyone out there? > > Patch can be retrieved from > http://rquadling.php1h.com/ini_patch.diff.txt > > Regards, > > Richard Quadlng. > > On 18/07/06, Richard Quadling <[EMAIL PROTECTED]> wrote: > > The supplied patch enhances PHP's .INI from ... > > > > php-%sapi-name%.ini > > > > to ... > > > > php%php-version%-%sapi-module-name%.ini > > > php%php-major-version%.%php-minor-version%.%php-release-version%-%sapi > > -module-name%.ini > > php%php-major-version%.%php-minor-version%-%sapi-module-name%.ini > > php%php-major-version%-%sapi-module-name%.ini > > > > with the original as a fallback. > > > > e.g. > > > > from > > > > php-isapi.ini > > > > to > > > > php5.2.0-dev-isapi.ini > > php5.1.4-isapi.ini > > php5.0-isapi.ini > > php5-isapi.ini > > php-isapi.ini > > > > (Just examples - all combinations are valid). > > > > > > With the INI files, the most specific one is looked for > first and each > > check gets less specific until a file is found. > > > > > > > > The supplied patches also do the same work with the Windows > Registry. > > > > Currently the registry key examined is ... > > > > SOFTWARE\\PHP > > > > This is extended to ... > > > > SOFTWARE\\PHP\\V5\\Per Directory Values SOFTWARE\\PHP\\V5.1\\Per > > Directory Values SOFTWARE\\PHP\\V5.1.4\\Per Directory Values > > SOFTWARE\\PHP\\V5.2.0-dev\\Per Directory Values > > > > The more specific settings will override the less specific settings. > > > > And the supplied patches allow for the location of the ini > file on a > > per PHP version basis... > > > > SOFTWARE\\PHP\\V5\\IniFilePath > > SOFTWARE\\PHP\\V5.1\\IniFilePath > > SOFTWARE\\PHP\\V5.1.4\\IniFilePath > > SOFTWARE\\PHP\\V5.2.0-dev\\IniFilePath > > > > The more specific paths will be examined before the less > specific paths. > > > > > > NOTE: I am NOT able to verify this code as I am not yet able to > > compile PHP. I'm still learning this, so please accept my apologies > > for any syntax errors, bugs. I'm more than willing to fix > them! And if > > anyone has used MS VC++ Express Edition to build PHP, I'd be REALLY > > grateful to have any notes/comments about the process. > > > > Thanks, > > > > Richard Quadling. > > > > > > -- > > ----- > > Richard Quadling > > Zend Certified Engineer : > > http://zend.com/zce.php?c=ZEND002498&r=213474731 > > > > > > > > > -- > ----- > Richard Quadling > Zend Certified Engineer : > http://zend.com/zce.php?c=ZEND002498&r=213474731 > "Standing on the shoulders of some very clever giants!" > > -- > PHP Internals - PHP Runtime Development Mailing List To > unsubscribe, visit: http://www.php.net/unsub.php >
-- ----- Richard Quadling Zend Certified Engineer : http://zend.com/zce.php?c=ZEND002498&r=213474731 "Standing on the shoulders of some very clever giants!"
Index: main/php_ini.c =================================================================== RCS file: /repository/php-src/main/php_ini.c,v retrieving revision 1.143 diff -u -r1.143 php_ini.c --- main/php_ini.c 4 Jul 2006 06:38:32 -0000 1.143 +++ main/php_ini.c 18 Jul 2006 08:36:34 -0000 @@ -293,6 +293,7 @@ static const char paths_separator[] = { ZEND_PATHS_SEPARATOR, 0 }; #ifdef PHP_WIN32 char *reg_location; + int version_specific; #endif env_location = getenv("PHPRC"); @@ -318,14 +319,17 @@ #ifdef PHP_WIN32 /* Add registry location */ - reg_location = GetIniPathFromRegistry(); - if (reg_location != NULL) { - if (*php_ini_search_path) { - strcat(php_ini_search_path, paths_separator); + /* RAQ : Add version specific registry location */ + for (version_specific = MAX_VERSION_SPECIFIC ; version_specific >= NOT_VERSION_SPECIFIC ; --version_specific) + { + reg_location = GetIniPathFromRegistry(version_specific); + if (reg_location != NULL) { + if (*php_ini_search_path) { + strcat(php_ini_search_path, paths_separator); + } + strcat(php_ini_search_path, reg_location); + efree(reg_location); } - strcat(php_ini_search_path, reg_location); - efree(reg_location); - } #endif /* Add cwd (only with CLI) */ @@ -428,6 +432,50 @@ } } } + /* RAQ : Search php%php-version%-%sapi-module-name%.ini file in search path */ + if (!fh.handle.fp) { + const char *fmt = "php%s-%s.ini"; + char *ini_fname = emalloc(strlen(fmt) + strlen(sapi_module.name) + strlen(PHP_VERSION)); + sprintf(ini_fname, fmt, PHP_VERSION, sapi_module.name); + fh.handle.fp = php_fopen_with_path(ini_fname, "r", php_ini_search_path, &php_ini_opened_path TSRMLS_CC); + efree(ini_fname); + if (fh.handle.fp) { + fh.filename = php_ini_opened_path; + } + } + /* RAQ : Search php%php-major-version%.%php-minor-version%.%php-release-version%-%sapi-module-name%.ini file in search path */ + if (!fh.handle.fp) { + const char *fmt = "php%d.%d.%d-%s.ini"; + char *ini_fname = emalloc(strlen(fmt) + strlen(sapi_module.name) + 6); + sprintf(ini_fname, fmt, PHP_MAJOR_VERSION, PHP_MINOR_VERSION, PHP_RELEASE_VERSION, sapi_module.name); + fh.handle.fp = php_fopen_with_path(ini_fname, "r", php_ini_search_path, &php_ini_opened_path TSRMLS_CC); + efree(ini_fname); + if (fh.handle.fp) { + fh.filename = php_ini_opened_path; + } + } + /* RAQ : Search php%php-major-version%.%php-minor-version%-%sapi-module-name%.ini file in search path */ + if (!fh.handle.fp) { + const char *fmt = "php%d.%d-%s.ini"; + char *ini_fname = emalloc(strlen(fmt) + strlen(sapi_module.name) + 4); + sprintf(ini_fname, fmt, PHP_MAJOR_VERSION, PHP_MINOR_VERSION, sapi_module.name); + fh.handle.fp = php_fopen_with_path(ini_fname, "r", php_ini_search_path, &php_ini_opened_path TSRMLS_CC); + efree(ini_fname); + if (fh.handle.fp) { + fh.filename = php_ini_opened_path; + } + } + /* RAQ : Search php%php-major-version%-%sapi-module-name%.ini file in search path */ + if (!fh.handle.fp) { + const char *fmt = "php%d-%s.ini"; + char *ini_fname = emalloc(strlen(fmt) + strlen(sapi_module.name) + 2); + sprintf(ini_fname, fmt, PHP_MAJOR_VERSION, sapi_module.name); + fh.handle.fp = php_fopen_with_path(ini_fname, "r", php_ini_search_path, &php_ini_opened_path TSRMLS_CC); + efree(ini_fname); + if (fh.handle.fp) { + fh.filename = php_ini_opened_path; + } + } /* Search php-%sapi-module-name%.ini file in search path */ if (!fh.handle.fp) { const char *fmt = "php-%s.ini"; Index: win32/php_registry.h =================================================================== RCS file: /repository/php-src/win32/php_registry.h,v retrieving revision 1.4 diff -u -r1.4 php_registry.h --- win32/php_registry.h 19 Oct 2003 10:22:21 -0000 1.4 +++ win32/php_registry.h 18 Jul 2006 08:36:34 -0000 @@ -1,8 +1,17 @@ #ifndef PHP_REGISTRY_H #define PHP_REGISTRY_H +/* RAQ : Constants to assist in version specificness. */ +#define NOT_VERSION_SPECIFIC 0 +#define MAJOR_VERSION_SPECIFIC 1 +#define MINOR_VERSION_SPECIFIC 2 +#define RELEASE_VERSION_SPECIFIC 3 +#define EXTRA_VERSION_SPECIFIC 4 +/* Maximum version specificness for for() loops. */ +#define MAX_VERSION_SPECIFIC 4 void UpdateIniFromRegistry(char *path TSRMLS_DC); -char *GetIniPathFromRegistry(); +/* RAQ : Allow for version specificness */ +char *GetIniPathFromRegistry(int version_specific); #endif /* PHP_REGISTRY_H */ Index: win32/registry.c =================================================================== RCS file: /repository/php-src/win32/registry.c,v retrieving revision 1.16 diff -u -r1.16 registry.c --- win32/registry.c 14 Mar 2005 12:42:05 -0000 1.16 +++ win32/registry.c 18 Jul 2006 08:36:34 -0000 @@ -3,15 +3,66 @@ #define PHP_REGISTRY_KEY "SOFTWARE\\PHP" +#include "php_registry.h" + void UpdateIniFromRegistry(char *path TSRMLS_DC) { char *p, *orig_path; HKEY MainKey; char *strtok_buf = NULL; - if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, PHP_REGISTRY_KEY "\\Per Directory Values", 0, KEY_READ, &MainKey)!=ERROR_SUCCESS) { - return; - } + /* RAQ : Version specificness */ + int version_specific; + char * reg_key; + + /* RAQ : Get default and then version specific entries. */ + /** + version_specific has the following meanings + 0 = No additional subkeys - SOFTWARE\\PHP\\Per Directory Values + 1 = PHP_MAJOR_VERSION added - SOFTWARE\\PHP\\V99\\Per Directory Values + 2 = PHP_MINOR_VERSION added - SOFTWARE\\PHP\\V99.99\\Per Directory Values + 3 = PHP_RELEASE_VERSION added - SOFTWARE\\PHPV99.99.99\\Per Directory Values + 4 = PHP_EXTRA_VERSION added - SOFTWARE\\PHP\\V99.99.99-dev\\Per Directory Values - Actually uses the full PHP_VERSION. + **/ + for (version_specific = NOT_VERSION_SPECIFIC ; version_specific <= MAX_VERSION_SPECIFIC ; ++version_specific) + { + /* RAQ : Build key which may include version specificness */ + switch(version_specific) + { + case MAJOR_VERSION_SPECIFIC : + reg_key = (char *) emalloc(strlen(PHP_REGISTRY_KEY) + strlen("\\99\\Per Directory Values")); + sprintf(reg_key, "%s\\%d\\Per Directory Values", + PHP_REGISTRY_KEY, + PHP_MAJOR_VERSION); + break; + case MINOR_VERSION_SPECIFIC : + reg_key = (char *) emalloc(strlen(PHP_REGISTRY_KEY) + strlen("\\99.99\\Per Directory Values")); + sprintf(reg_key, "%s\\%d.%d\\Per Directory Values", + PHP_REGISTRY_KEY, + PHP_MAJOR_VERSION, PHP_MINOR_VERSION); + break; + case RELEASE_VERSION_SPECIFIC : + reg_key = (char *) emalloc(strlen(PHP_REGISTRY_KEY) + strlen("\\99.99.99\\Per Directory Values")); + sprintf(reg_key, "%s\\%d.%d.%d\\Per Directory Values", + PHP_REGISTRY_KEY, + PHP_MAJOR_VERSION, PHP_MINOR_VERSION, PHP_RELEASE_VERSION); + break; + case EXTRA_VERSION_SPECIFIC : + reg_key = (char *) emalloc(strlen(PHP_REGISTRY_KEY) + strlen("\\Per Directory Values") + strlen(PHP_VERSION)); + sprintf(reg_key, "%s\\%s\\Per Directory Values", + PHP_REGISTRY_KEY, + PHP_VERSION); + break; + default : + reg_key = (char *) emalloc(strlen(PHP_REGISTRY_KEY) + strlen("\\Per Directory Values")); + sprintf(reg_key, "%s\\Per Directory Values", PHP_REGISTRY_KEY); + break; + } + /* RAQ END : Continue with appropriate key. */ + + if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, reg_key, 0, KEY_READ, &MainKey)!=ERROR_SUCCESS) { + return; + } orig_path = path = estrdup(path); @@ -91,16 +142,53 @@ } RegCloseKey(MainKey); efree(orig_path); + } /* RAQ : End of version specificness loop */ } #define PHPRC_REGISTRY_NAME "IniFilePath" -char *GetIniPathFromRegistry() +char *GetIniPathFromRegistry(int version_specific) { char *reg_location = NULL; HKEY hKey; - - if(RegOpenKeyEx(HKEY_LOCAL_MACHINE, PHP_REGISTRY_KEY, 0, KEY_READ, &hKey) == ERROR_SUCCESS) { + char *reg_key = NULL; + + // RAQ : Determine which key to use - may include version specificiness. + switch(version_specific) + { + case MAJOR_VERSION_SPECIFIC : + reg_key = (char *) emalloc(strlen(PHP_REGISTRY_KEY) + strlen("\\99")); + sprintf(reg_key, "%s\\%d", + PHP_REGISTRY_KEY, + PHP_MAJOR_VERSION); + break; + case MINOR_VERSION_SPECIFIC : + reg_key = (char *) emalloc(strlen(PHP_REGISTRY_KEY) + strlen("\\99.99")); + sprintf(reg_key, "%s\\%d.%d", + PHP_REGISTRY_KEY, + PHP_MAJOR_VERSION, PHP_MINOR_VERSION); + break; + case RELEASE_VERSION_SPECIFIC : + reg_key = (char *) emalloc(strlen(PHP_REGISTRY_KEY) + strlen("\\99.99.99")); + sprintf(reg_key, "%s\\%d.%d.%d", + PHP_REGISTRY_KEY, + PHP_MAJOR_VERSION, PHP_MINOR_VERSION, PHP_RELEASE_VERSION); + break; + case EXTRA_VERSION_SPECIFIC : + reg_key = (char *) emalloc(strlen(PHP_REGISTRY_KEY) + strlen("\\") + strlen(PHP_VERSION)); + sprintf(reg_key, "%s\\%s", + PHP_REGISTRY_KEY, + PHP_VERSION); + break; + default : + reg_key = (char *) emalloc(strlen(PHP_REGISTRY_KEY)); + sprintf(reg_key, "%s", PHP_REGISTRY_KEY); + break; + } + /* RAQ END : Continue with appropriate key. */ + + /* RAQ : Use potentially version specific registry key : if(RegOpenKeyEx(HKEY_LOCAL_MACHINE, PHP_REGISTRY_KEY, 0, KEY_READ, &hKey) == ERROR_SUCCESS) {*/ + if(RegOpenKeyEx(HKEY_LOCAL_MACHINE, reg_key, 0, KEY_READ, &hKey) == ERROR_SUCCESS) { DWORD buflen = MAXPATHLEN; reg_location = emalloc(MAXPATHLEN+1); if(RegQueryValueEx(hKey, PHPRC_REGISTRY_NAME, 0, NULL, reg_location, &buflen) != ERROR_SUCCESS) {
-- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php