Description
int
dl ( string library)
Loads the PHP extension given by the parameter
library_ The library
parameter is only the filename of the extension to
load which also depends on your platform_ For example, the sockets extension (if compiled as a shared
module, not the default!) would be called sockets_so
on unix platforms whereas it is called
php_sockets_dll on the Windows platform_
Devuelve TRUE si todo se
llevó a cabo correctamente, FALSE en caso
de fallo_ If the functionality of loading modules is not available
(see Note) or has been disabled (either by turning it off
enable_dl or by enabling safe mode
in php_ini) an E_ERROR is emitted
and execution is stopped_ If dl() fails because the
specified library couldn't be loaded, in addition to FALSE an
E_WARNING message is emitted_
Use extension_loaded() to test whether a given
extension is already available or not_ This works on both built_in
extensions and dynamically loaded ones (either through php_ini
or dl())_
Ejemplo 1_ dl() examples <?php
// Example loading an extension based on OS
if (!extension_loaded('sqlite')) {
if (strtoupper(substr(PHP_OS, 0,3) == 'WIN')) {
dl('php_sqlite_dll');
} else {
dl('sqlite_so');
}
}
// Or, the PHP_SHLIB_SUFFIX constant is available as of PHP 4_3_0
if (!extension_loaded('sqlite')) {
$prefix = (PHP_SHLIB_SUFFIX == 'dll') ? 'php_' : '';
dl($prefix _ 'sqlite_' _ PHP_SHLIB_SUFFIX);
}
?> |
|
The directory where the extension is loaded from depends on your
platform:
Windows _ If not explicitly set in the php_ini, the extension is
loaded from c:\php4\extensions\ by default_
Unix _ If not explicitly set in the php_ini, the default extension
directory depends on
whether PHP has been built with __enable_debug or
not
whether PHP has been built with (experimental) ZTS (Zend Thread Safety)
support or not
the current internal ZEND_MODULE_API_NO (Zend
internal module API number, which is basically the date on which a
major module API change happened, e_g_ 20010901)
Taking into account the above, the directory then defaults to
<install_dir>/lib/php/extensions/ <debug_or_not>_<zts_or_not>_ZEND_MODULE_API_NO,
e_g_
/usr/local/php/lib/php/extensions/debug_non_zts_20010901
or
/usr/local/php/lib/php/extensions/no_debug_zts_20010901_
Nota:
dl() is not supported in
multithreaded Web servers_ Use the extensions
statement in your php_ini when operating under such
an environment_ However, the CGI and
CLI build are not
affected !
Nota:
dl() is case sensitive on unix platforms_
See also
Extension Loading Directives
and extension_loaded()_