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:

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

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.


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 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:

 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 



    Sams Teach Yourself PHP in 10 Minutes
    Sams Teach Yourself PHP in 10 Minutes
    ISBN: 0672327627
    EAN: 2147483647
    Year: 2005
    Pages: 151
    Authors: Chris Newman

    flylib.com © 2008-2017.
    If you may any questions please contact us: flylib@qtcs.net