(PHP 4, PHP 5, PHP 7)
dl — Loads a PHP extension at runtime
$library
)
Loads the PHP extension given by the parameter
library
.
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()).
This function was removed from most SAPIs in PHP 5.3.0, and was removed from PHP-FPM in PHP 7.0.0.
library
This 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.
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:\php5\ by default.
Unix - If not explicitly set in the php.ini, the default extension directory depends on
Întoarce valoarea TRUE
în cazul
succesului sau FALSE
în cazul eșecului. If the functionality of loading modules is not available
or has been disabled (either by setting
enable_dl off or by enabling modul securizat
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.
Example #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 using PHP_SHLIB_SUFFIX constant
if (!extension_loaded('sqlite')) {
$prefix = (PHP_SHLIB_SUFFIX === 'dll') ? 'php_' : '';
dl($prefix . 'sqlite.' . PHP_SHLIB_SUFFIX);
}
?>
Versiune | Descriere |
---|---|
7.0.0 | dl() is disabled in PHP-FPM. |
5.3.9 | dl() is enabled in PHP-FPM, albeit discouraged. |
5.3.0 | dl() is now disabled in some SAPIs due to stability issues. The only SAPIs that allow dl() are CLI and Embed. Use the Extension Loading Directives instead. |
Notă:
dl() is not supported when PHP is built with ZTS support. Use the Extension Loading Directives instead.
Notă:
dl() is case sensitive on Unix platforms.
Notă: Această funcție este dezactivată atunci când PHP rulează în modul securizat.