dl

Loads a PHP extension at runtime

Syntax

dl(string $extension_filename): bool

Parameters

extension_filename

The filename of the extension to load.

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, and 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.

Return

Returns true on success or false on failure.

If the functionality of loading modules is not available or has been disabled (by setting enable_dl off 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.

Examples

1

<?

// load 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');
    }
}

?>

			
		

2

<?

// load an extension based on PHP_SHLIB_SUFFIX
if(!extension_loaded('sqlite'))
{
    $prefix = (PHP_SHLIB_SUFFIX === 'dll') ? 'php_' : '';
    dl($prefix . 'sqlite.' . PHP_SHLIB_SUFFIX);
}

?>

			
		

assert

assert_options

cli_get_process_title

cli_set_process_title

extension_loaded

gc_collect_cycles

gc_disable

gc_enable

gc_enabled

gc_mem_caches

gc_status

get_cfg_var

get_current_user

get_defined_constants

get_extension_funcs

get_include_path

get_included_files

get_loaded_extensions

get_required_files

get_resources

getenv

getlastmod

getmygid

getmyinode

getmypid

getmyuid

getopt

getrusage

ini_alter

ini_get

ini_get_all

ini_restore

ini_set

memory_get_peak_usage

memory_get_usage

memory_reset_peak_usage

php_ini_loaded_file

php_ini_scanned_files

php_sapi_name

php_uname

phpcredits

phpinfo

phpversion

putenv

set_include_path

set_time_limit

sys_get_temp_dir

version_compare

zend_thread_id

zend_version

PHP

Home Menu