dl

Descrierea

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()).

Avertizare

This function was removed from most SAPIs in PHP 5.3.0, and was removed
from PHP-FPM in PHP 7.0.0.

Parametri

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

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.

Valorile întoarse

Î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.

Telling me 'This function has been removed from some SAPIs in PHP 5.3.' is pretty much useless and I feel mocked. Or do the writers of the documentation don't know from which SAPIs it has been removed?

If you need to load an extension from the CURRENT local directory because you do not have privelages to place the extension in your servers PHP extensions directory, this function i wrote may be of use to you

<?php
/*
Function: dl_local()
Reference: http://us2.php.net/manual/en/function.dl.php Author: Brendon Crawford <endofyourself |AT| yahoo>
Usage: dl_local( "mylib.so" );
Returns: Extension Name (NOT the extension filename however)
NOTE:
This function can be used when you need to load a PHP extension (module,shared object,etc..),
but you do not have sufficient privelages to place the extension in the proper directory where it can be loaded. This function
will load the extension from the CURRENT WORKING DIRECTORY only.
If you need to see which functions are available within a certain extension,
use "get_extension_funcs()". Documentation for this can be found at
"http://us2.php.net/manual/en/function.get-extension-funcs.php".
*/

Like with eval(), the only correct way to use dl() is to not use it.Test if a function(s) you intend to use are available.If not, complain to the user or implement a workaround.Not to mention dl() issues in a multithreading environment.

Changelog 5.3: 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.

If using PEAR libraries that try to load extensions, like Image_Transform which will try to load ImageMagik, and the "enable_dl" directive is set to 1 in your php.ini, you may end up with a hard to find error (white screen of death).

One "solution" is to change the enable_dl directive to 0 in the php.ini. It may have adverse affects if you are using php on command line that requires the "dl" function, but I think in most cases its okay.