Loadable Modules
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 Demand
You 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:
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.
./configure --with-mysql --with-sockets=shared
![]() | Loadable Extensions Whether the dl function is available is governed by the enable_dl directive in php.ini. You may find that on a shared web hosting service, this feature is not available to you. |
Loading Modules on Startup
If 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:
On a Windows web server, the configuration lines need to look like this, to reflect the difference in filenames between the two platforms:
extension=imap.so
extension=sockets.so
extension=php_imap.dll
extension=php_sockets.dll