I wonder why extension_dir couldn't seek the modules in more that one 
directory. All known interpreters (perl, ruby, python) can read modules from 
the different directories. The layout is usually:

/usr/lib/php - system modules installed from package
/usr/local/lib/php - manually installed modules

My proposition is to extend extension_dir setting and allow to set the 
directories separated with colon sign.

-- 
 .''`.    Piotr Roszatycki, Netia SA
: :' :    mailto:[EMAIL PROTECTED]
`. `'     mailto:[EMAIL PROTECTED]
  `-
The extension_dir can contains path list separated with colon.

diff -Nru php-5.0.4.orig/ext/standard/dl.c php-5.0.4/ext/standard/dl.c
--- php-5.0.4.orig/ext/standard/dl.c	2005-03-21 09:34:37 +0100
+++ php-5.0.4/ext/standard/dl.c	2005-04-05 11:48:00 +0200
@@ -46,6 +46,11 @@
 
 #endif /* defined(HAVE_LIBDL) || HAVE_MACH_O_DYLD_H */
 
+#include <sys/stat.h>
+#if HAVE_UNISTD_H
+#include <unistd.h>
+#endif
+
 
 /* {{{ proto int dl(string extension_filename)
    Load a PHP extension at runtime */
@@ -101,6 +106,8 @@
 	zend_module_entry *(*get_module)(void);
 	int error_type;
 	char *extension_dir;
+	char *tmp = NULL, *ptr = NULL;
+	struct stat buf;
 
 	if (type==MODULE_PERSISTENT) {
 		/* Use the configuration hash directly, the INI mechanism is not yet initialized */
@@ -111,24 +118,54 @@
 		extension_dir = PG(extension_dir);
 	}
 
-	if (type==MODULE_TEMPORARY) {
-		error_type = E_WARNING;
-	} else {
-		error_type = E_CORE_WARNING;
+	if (extension_dir && extension_dir[0]) {
+		tmp = emalloc(strlen(extension_dir));
+		strcpy(tmp, extension_dir);
+		extension_dir = tmp;
 	}
 
-	if (extension_dir && extension_dir[0]){
-		int extension_dir_len = strlen(extension_dir);
+	while (1) {
 
-		libpath = emalloc(extension_dir_len+Z_STRLEN_P(file)+2);
+		if (extension_dir && extension_dir[0] && (ptr = strchr(extension_dir, ':')) != NULL) {
+			ptr[0] = 0;
+			ptr++;
+		}
 
-		if (IS_SLASH(extension_dir[extension_dir_len-1])) {
-			sprintf(libpath, "%s%s", extension_dir, Z_STRVAL_P(file)); /* SAFE */
+		if (type==MODULE_TEMPORARY) {
+			error_type = E_WARNING;
 		} else {
-			sprintf(libpath, "%s%c%s", extension_dir, DEFAULT_SLASH, Z_STRVAL_P(file)); /* SAFE */
+			error_type = E_CORE_WARNING;
 		}
-	} else {
-		libpath = estrndup(Z_STRVAL_P(file), Z_STRLEN_P(file));
+
+		if (extension_dir && extension_dir[0]){
+			int extension_dir_len = strlen(extension_dir);
+
+			libpath = emalloc(extension_dir_len+Z_STRLEN_P(file)+2);
+
+			if (IS_SLASH(extension_dir[extension_dir_len-1])) {
+				sprintf(libpath, "%s%s", extension_dir, Z_STRVAL_P(file)); /* SAFE */
+			} else {
+				sprintf(libpath, "%s%c%s", extension_dir, DEFAULT_SLASH, Z_STRVAL_P(file)); /* SAFE */
+			}
+		} else {
+			libpath = estrndup(Z_STRVAL_P(file), Z_STRLEN_P(file));
+		}
+
+		if (stat(libpath, &buf) == 0) {
+			break;
+		}
+
+		if (!ptr || !ptr[0]) {
+			break;
+		}
+
+		efree(libpath);
+
+		extension_dir = ptr;
+	}
+
+	if (tmp) {
+		efree(tmp);
 	}
 
 	/* load dynamic symbol */

-- 
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to