-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Allow loading extensions by name #1741
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
php.ini-development
Outdated
; | ||
; ... or under UNIX: | ||
; | ||
; extension=msql.so |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The Windows/UNIX distinction in this comment is no longer necessary.
3b55a4a
to
49fe831
Compare
49fe831
to
0d937c7
Compare
RFC is under discussion: https://wiki.php.net/rfc/load-ext-by-name |
@flaupretre fix conflicts please :) Please push forward with this RFC, alternatively, if you consider this work abandoned, please close this PR. |
c4367ee
to
483a8df
Compare
483a8df
to
c4367ee
Compare
c4367ee
to
406c866
Compare
In voting: https://wiki.php.net/rfc/load-ext-by-name |
@emirb Thanks for the notice :) |
53a4cee
to
bd5cf8e
Compare
The RFC was approved and will be merged in 7.2. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was about to merge this, fixing the minor nits along the way, but the fwrite(stderr, ...) concerns me in particular.
NEWS
Outdated
@@ -15,6 +16,9 @@ PHP NEWS | |||
- Standard | |||
. Compatibility with libargon2 versions 20161029 and 20160821. | |||
(charlesportwoodii at erianna dot com) | |||
. Allow loading PHP and Zend extensions by name (instead of filename). Also | |||
add support for extension name in dl() function. | |||
(francois at tekwire dot net) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Move this up to Core
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
ext/standard/dl.c
Outdated
@@ -81,10 +81,13 @@ PHPAPI PHP_FUNCTION(dl) | |||
PHPAPI int php_load_extension(char *filename, int type, int start_now) | |||
{ | |||
void *handle; | |||
char *libpath; | |||
char *libpath, | |||
*orig_libpath; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Move these to single lines or redeclare the type, please.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
ext/standard/dl.c
Outdated
} else { | ||
spprintf(&libpath, 0, "%s%cphp_%s." PHP_SHLIB_SUFFIX, extension_dir, DEFAULT_SLASH, filename); /* SAFE */ | ||
} | ||
#else |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Trailing whitespace here and in several other places. Please clean that up.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
main/php_ini.c
Outdated
} | ||
#endif | ||
if (VCWD_ACCESS(libpath, F_OK)) { | ||
fprintf(stderr, "Cannot access Zend extension %s (Tried: %s, %s)\n", filename, orig_libpath, libpath); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps I missed the discussion, but why are you directly writing to stderr
here? Surely we can zend_error()
instead.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just copied the same error mechanism as used in zend_load_extension() when the file cannot be loaded. I don't know why it calls 'fprintf(stderr' instead of zend_error(). I can change both if you think it's safe.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Without having looked deeper into it, but I guess it could be that zend_error() is unsafe to call if this is called in early startup, if not then I don't see a reason not to make it use the API
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we want to keep this code consistent with the way error is raised in zend_load_extension(), we should change both but, as you say, I'm not sure zend_error() can be called in every context where zend_load_extension() is executed, especially in the case of '-z' command line options.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree, as zend_load_extension use fprintf, shoudl also be used here.
But, IIUC, this is only used for better report about "tried" file name, so perhaps the second if (VCWD_ACCESS
can be ignored.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@remicollet Sure, if the file does not exist, zend_load_extension() will fail and we don't need to check before we call it but I found it quite valuable for the user to display an error message containing the different paths we tried before giving up. That's why we keep the 1st path we tried in orig_libpath and display it in the error message.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@flaupretre indeed, (so I understand correctly). Fine for me.
bd5cf8e
to
53e9b78
Compare
Allow extension name as INI 'extension=' and dl() argument No BC break, as file name is still accepted. When using the '-z' command line option (CLI/CGI), an absolute file name must still be provided (nothing changed here) Change comments in example INI files
53e9b78
to
96c95de
Compare
Status : RFC is approved for inclusion in 7.2
This PR provides a portable way to configure the list of PHP extensions to load.
Today, 'extension=' lines in php.ini must contain the extension's file name. Unfortunately, this file name depends on the platform PHP is running on. A 'php_' prefix must even be added on Windows.
While seasoned PHP administrators are used to this mechanism, this is a problem when writing documentation for beginners, or when writing platform-agnostic scripts. A typical example is the coexistence of a Windows development environment and a Linux production. In such cases, it is impossible to write a single configuration file that will work in both environments, forcing developers to manually maintain two separate versions of the file.
This PR allows to specify extensions (PHP and Zend) by their extension name.
Example :
'extension=bz2', for example, will cause PHP to load a file named 'php_bz2.dll' on Windows, and a file named 'bz2.so' on LInux.
Note that filenames are still accepted and handled as before. So, this extension does not cause any BC break.
Example php.ini files are modified because loading extensions by name becomes the recommended way of configuring additional extensions to load.
Cases where the extension name is accepted :
Cases where the extension name cannot be used :
References: