Name

dl()

Synopsis

    int dl ( string extension_name )

Use the dl() function to load an extension at runtime, passing the name of the extension to load as its only parameter. Note that there are cross-platform considerations to using dl() that are discussed later. The downside to using dl() is that it needs to dynamically load and unload the extension each time your scripts run—this ends up being a great deal slower than running PHP as a web server module, where the extensions are loaded just once and kept in memory.

One last warning: using dl() with multithreaded web servers (such as Apache 2) will simply not work; you will need to use the static method of editing your php.ini file and restarting the server.

Here is an example of dl() on both Windows and Unix:

    dl('php_imap.dll'); // Windows
    dl('imap.so'); // Unix

Get PHP in a Nutshell now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.