<?php
include_once $_SERVER['DOCUMENT_ROOT'] . '/include/shared-manual.inc';
$TOC = array();
$TOC_DEPRECATED = array();
$PARENTS = array();
include_once dirname(__FILE__) ."/toc/ref.info.inc";
$setup = array (
  'home' => 
  array (
    0 => 'index.php',
    1 => 'PHP Manual',
  ),
  'head' => 
  array (
    0 => 'UTF-8',
    1 => 'en',
  ),
  'this' => 
  array (
    0 => 'function.dl.php',
    1 => 'dl',
    2 => 'Loads a PHP extension at runtime',
  ),
  'up' => 
  array (
    0 => 'ref.info.php',
    1 => 'PHP Options/Info Functions',
  ),
  'prev' => 
  array (
    0 => 'function.cli-set-process-title.php',
    1 => 'cli_set_process_title',
  ),
  'next' => 
  array (
    0 => 'function.extension-loaded.php',
    1 => 'extension_loaded',
  ),
  'alternatives' => 
  array (
  ),
  'source' => 
  array (
    'lang' => 'en',
    'path' => 'reference/info/functions/dl.xml',
  ),
  'history' => 
  array (
  ),
);
$setup["toc"] = $TOC;
$setup["toc_deprecated"] = $TOC_DEPRECATED;
$setup["parents"] = $PARENTS;
manual_setup($setup);

contributors($setup);

?>
<div id="function.dl" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">dl</h1>
  <p class="verinfo">(PHP 4, PHP 5, PHP 7, PHP 8)</p><p class="refpurpose"><span class="refname">dl</span> &mdash; <span class="dc-title">Loads a PHP extension at runtime</span></p>

 </div>

 <div class="refsect1 description" id="refsect1-function.dl-description">
  <h3 class="title">Description</h3>
  <div class="methodsynopsis dc-description">
   <span class="methodname"><strong>dl</strong></span>(<span class="methodparam"><span class="type"><a href="language.types.string.php" class="type string">string</a></span> <code class="parameter">$extension_filename</code></span>): <span class="type"><a href="language.types.boolean.php" class="type bool">bool</a></span></div>

  <p class="para rdfs-comment">
   Loads the PHP extension given by the parameter
   <code class="parameter">extension_filename</code>.
  </p>
  <p class="para">
   Use <span class="function"><a href="function.extension-loaded.php" class="function">extension_loaded()</a></span> to test whether a given
   extension is already available or not. This works on both built-in
   extensions and dynamically loaded ones (either through <var class="filename">php.ini</var> or
   <span class="function"><strong>dl()</strong></span>).
  </p>
  <div class="warning"><strong class="warning">Warning</strong>
   <p class="simpara">
    This function is only available for the <abbr title="Command Line Interpreter/Interface">CLI</abbr> and embed <abbr title="Server Application Programming Interface">SAPI</abbr>s,
    and the <abbr title="Common Gateway Interface">CGI</abbr> <abbr title="Server Application Programming Interface">SAPI</abbr> when run from the command line.
   </p>
  </div>
 </div>


 <div class="refsect1 parameters" id="refsect1-function.dl-parameters">
  <h3 class="title">Parameters</h3>
  <p class="para">
   <dl>
    
     <dt><code class="parameter">extension_filename</code></dt>
     <dd>
      <p class="para">
       This parameter is <em>only</em> the filename of the
       extension to load which also depends on your platform. For example,
       the <a href="ref.sockets.php" class="link">sockets</a> extension (if compiled
       as a shared module, not the default!) would be called 
       <var class="filename">sockets.so</var> on Unix platforms whereas it is called
       <var class="filename">php_sockets.dll</var> on the Windows platform.
      </p>
      <p class="para">
       The directory where the extension is loaded from depends on your
       platform:
      </p>
      <p class="para">
       Windows - If not explicitly set in the <var class="filename">php.ini</var>, the extension is
       loaded from <var class="filename">C:\php5\</var> by default.
      </p>
      <p class="para">
       Unix - If not explicitly set in the <var class="filename">php.ini</var>, the default extension
       directory depends on
       <ul class="itemizedlist">
        <li class="listitem">
         <span class="simpara">
          whether PHP has been built with <code class="literal">--enable-debug</code>
          or not
         </span>
        </li>
        <li class="listitem">
         <span class="simpara">
          whether PHP has been built with ZTS (Zend Thread Safety)
          support or not
         </span>
        </li>
        <li class="listitem">
         <span class="simpara">
          the current internal <code class="literal">ZEND_MODULE_API_NO</code> (Zend
          internal module API number, which is basically the date on which a
          major module API change happened, e.g. <code class="literal">20010901</code>)
         </span>
        </li>
       </ul>
       Taking into account the above, the directory then defaults to
       <code class="literal">&lt;install-dir&gt;/lib/php/extensions/ &lt;debug-or-not&gt;-&lt;zts-or-not&gt;-ZEND_MODULE_API_NO</code>,
       e.g.
       <var class="filename">/usr/local/php/lib/php/extensions/debug-non-zts-20010901</var>
       or
       <var class="filename">/usr/local/php/lib/php/extensions/no-debug-zts-20010901</var>.
      </p>
     </dd>
    
   </dl>
  </p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-function.dl-returnvalues">
  <h3 class="title">Return Values</h3>
  <p class="para">
   Returns <strong><code><a href="reserved.constants.php#constant.true">true</a></code></strong> on success or <strong><code><a href="reserved.constants.php#constant.false">false</a></code></strong> on failure. If the functionality of loading modules is not available
   or has been disabled (by setting
   <a href="info.configuration.php#ini.enable-dl" class="link">enable_dl</a> off
   in <var class="filename">php.ini</var>) an <strong><code><a href="errorfunc.constants.php#constant.e-error">E_ERROR</a></code></strong> is emitted
   and execution is stopped. If <span class="function"><strong>dl()</strong></span> fails because the
   specified library couldn&#039;t be loaded, in addition to <strong><code><a href="reserved.constants.php#constant.false">false</a></code></strong> an
   <strong><code><a href="errorfunc.constants.php#constant.e-warning">E_WARNING</a></code></strong> message is emitted.
  </p>
 </div>


 <div class="refsect1 examples" id="refsect1-function.dl-examples">
  <h3 class="title">Examples</h3>
  <p class="para">
   <div class="example" id="example-1">
    <p><strong>Example #1 <span class="function"><strong>dl()</strong></span> examples</strong></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br /></span><span style="color: #FF8000">// Example loading an extension based on OS<br /></span><span style="color: #007700">if (!</span><span style="color: #0000BB">extension_loaded</span><span style="color: #007700">(</span><span style="color: #DD0000">'sqlite'</span><span style="color: #007700">)) {<br />    if (</span><span style="color: #0000BB">strtoupper</span><span style="color: #007700">(</span><span style="color: #0000BB">substr</span><span style="color: #007700">(</span><span style="color: #0000BB">PHP_OS</span><span style="color: #007700">, </span><span style="color: #0000BB">0</span><span style="color: #007700">, </span><span style="color: #0000BB">3</span><span style="color: #007700">)) === </span><span style="color: #DD0000">'WIN'</span><span style="color: #007700">) {<br />        </span><span style="color: #0000BB">dl</span><span style="color: #007700">(</span><span style="color: #DD0000">'php_sqlite.dll'</span><span style="color: #007700">);<br />    } else {<br />        </span><span style="color: #0000BB">dl</span><span style="color: #007700">(</span><span style="color: #DD0000">'sqlite.so'</span><span style="color: #007700">);<br />    }<br />}<br /><br /></span><span style="color: #FF8000">// Or using PHP_SHLIB_SUFFIX constant<br /></span><span style="color: #007700">if (!</span><span style="color: #0000BB">extension_loaded</span><span style="color: #007700">(</span><span style="color: #DD0000">'sqlite'</span><span style="color: #007700">)) {<br />    </span><span style="color: #0000BB">$prefix </span><span style="color: #007700">= (</span><span style="color: #0000BB">PHP_SHLIB_SUFFIX </span><span style="color: #007700">=== </span><span style="color: #DD0000">'dll'</span><span style="color: #007700">) ? </span><span style="color: #DD0000">'php_' </span><span style="color: #007700">: </span><span style="color: #DD0000">''</span><span style="color: #007700">;<br />    </span><span style="color: #0000BB">dl</span><span style="color: #007700">(</span><span style="color: #0000BB">$prefix </span><span style="color: #007700">. </span><span style="color: #DD0000">'sqlite.' </span><span style="color: #007700">. </span><span style="color: #0000BB">PHP_SHLIB_SUFFIX</span><span style="color: #007700">);<br />}<br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>
    </div>

   </div>
  </p>
 </div>


 <div class="refsect1 notes" id="refsect1-function.dl-notes">
  <h3 class="title">Notes</h3>
  <blockquote class="note"><p><strong class="note">Note</strong>: 
   <p class="para">
    <span class="function"><strong>dl()</strong></span> is case sensitive on Unix platforms.
   </p>
  </p></blockquote>
 </div>


 <div class="refsect1 seealso" id="refsect1-function.dl-seealso">
  <h3 class="title">See Also</h3>
  <p class="para">
   <ul class="simplelist">
    <li><a href="ini.core.php#ini.extension" class="link">Extension Loading Directives</a></li>
    <li><span class="function"><a href="function.extension-loaded.php" class="function" rel="rdfs-seeAlso">extension_loaded()</a> - Find out whether an extension is loaded</span></li>
   </ul>
  </p>
 </div>


</div><?php manual_footer($setup); ?>