|
PHP allows you to load certain extensions at runtime. This means that you can extend the functionality of PHP without needing to recompile from source. Loading Extensions on DemandYou use the dl function to dynamically load an extension module. You build extensions as dynamically loadable objects when PHP is compiled, by using the --with-EXTENSION=shared switch. For instance, running the following configure statement causes PHP to be compiled with MySQL support linked in but with socket support as a loadable extension: ./configure --with-mysql --with-sockets=shared The argument given to dl is the filename of the extension. In the case of the sockets extension, it would be called sockets.so on Linux/Unix but php_sockets.dll on Windows systems.
To check whether an extension is loaded into PHP, you use the extension_loaded function. Given an extension name argument, this function returns trUE or FALSE, depending on the presence of that extension. Note that PHP cannot tell whether an extension was loaded by using dl or is compiled in. Loading Modules on StartupIf you have extensions as loadable modules and want them to be loaded into PHP without needing to run dl in every script, you can use the extension directive in php.ini to provide a list of extensions to load at startup. Each extension is given on a separate line, and there is no limit to the number of extensions you can load in this way. The following lines from php.ini ensure that the sockets and imap extensions are loaded automatically on a Linux/Unix server: extension=imap.so extension=sockets.so On a Windows web server, the configuration lines need to look like this, to reflect the difference in filenames between the two platforms: extension=php_imap.dll extension=php_sockets.dll |
|