dl Loads a PHP extension at runtime php函数


dl

(PHP 4, PHP 5)

dlLoads a PHP extension at runtime

说明

bool dl ( string $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()).

Warning

This function has been removed from some SAPIs in PHP 5.3.

参数

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:php4extensions (PHP 4) or C:php5 (PHP 5) 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.

返回值

成功时返回 TRUE, 或者在失败时返回 FALSE. If the functionality of loading modules is not available or has been disabled (either by setting enable_dl off or by enabling 安全模式 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_OS03)) === '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);
}
?>

更新日志

版本 说明
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.

注释

Note:

dl() is not supported when PHP is built with ZTS support. Use the Extension Loading Directives instead.

Note:

dl() is case sensitive on Unix platforms.

Note: 当 PHP 运行在 安全模式 时,不能使用此函数。

参见

  • Extension Loading Directives
  • extension_loaded() - Find out whether an extension is loaded



相关阅读:
dngettext Plural version of dgettext
dns_check_record 别名 checkdnsrr
dns_get_mx 别名 getmxrr
dns_get_record Fetch DNS Resource Records associated with a hostname
dom_import_simplexml Gets a DOMElement object from a SimpleXMLElement object
dotnet_load 加载一个 DOTNET 模块
doubleval floatval 的别名
each 返回数组中当前的键/值对并将数组指针向前移动一步
easter_date 得到指定年份的复活节午夜时的Unix时间戳。
easter_days 得到指定年份的3月21日到复活节之间的天数
echo 输出一个或多个字符串
empty 检查一个变量是否为空
end 将数组的内部指针指向最后一个单元
ereg 正则表达式匹配
快速导航

Copyright © 2016 phpStudy |