<?xml version="1.0" encoding="utf-8"?>
<!-- $Revision$ -->
<refentry xml:id="function.curl-multi-exec" xmlns="http://docbook.org/ns/docbook">
 <refnamediv>
  <refname>curl_multi_exec</refname>
  <refpurpose>Run the sub-connections of the current cURL handle</refpurpose>
 </refnamediv>
 
 <refsect1 role="description">
  &reftitle.description;
  <methodsynopsis>
   <type>int</type><methodname>curl_multi_exec</methodname>
   <methodparam><type>resource</type><parameter>mh</parameter></methodparam>
   <methodparam><type>int</type><parameter role="reference">still_running</parameter></methodparam>
  </methodsynopsis>
  <para>
   Processes each of the handles in the stack.  This method can be called whether or not a handle
   needs to read or write data.
  </para> 
 </refsect1>

 <refsect1 role="parameters">
  &reftitle.parameters;
  <para>
   <variablelist>
    &curl.mh.description;
    <varlistentry>
     <term><parameter>still_running</parameter></term>
     <listitem>
      <para>
       A reference to a flag to tell whether the operations are still running.
      </para>
     </listitem>
    </varlistentry>
   </variablelist>
  </para>
 </refsect1>

 <refsect1 role="returnvalues">
  &reftitle.returnvalues;
  <para>
   A cURL code defined in the cURL <link linkend="curl.constants">Predefined Constants</link>.
  </para>
  <note>
   <para>
    This only returns errors regarding the whole multi stack. There might still have 
    occurred problems on individual transfers even when this function returns 
    <constant>CURLM_OK</constant>.
   </para>
  </note>
 </refsect1>
 
 <refsect1 role="examples">
  &reftitle.examples;
  <para>
   <example>
    <title><function>curl_multi_exec</function> example</title>
    <para>
     This example will create two cURL handles, add them to a multi
     handle, and process them asynchronously.
    </para>
    <programlisting role="php">
<![CDATA[
<?php
// create both cURL resources
$ch1 = curl_init();
$ch2 = curl_init();

// set URL and other appropriate options
curl_setopt($ch1, CURLOPT_URL, "http://lxr.php.net/");
curl_setopt($ch1, CURLOPT_HEADER, 0);
curl_setopt($ch2, CURLOPT_URL, "http://www.php.net/");
curl_setopt($ch2, CURLOPT_HEADER, 0);

//create the multiple cURL handle
$mh = curl_multi_init();

//add the two handles
curl_multi_add_handle($mh,$ch1);
curl_multi_add_handle($mh,$ch2);

$active = null;
//execute the handles
do {
    $mrc = curl_multi_exec($mh, $active);
} while ($mrc == CURLM_CALL_MULTI_PERFORM);

while ($active && $mrc == CURLM_OK) {
    if (curl_multi_select($mh) != -1) {
        do {
            $mrc = curl_multi_exec($mh, $active);
        } while ($mrc == CURLM_CALL_MULTI_PERFORM);
    }
}

//close the handles
curl_multi_remove_handle($mh, $ch1);
curl_multi_remove_handle($mh, $ch2);
curl_multi_close($mh);

?>
]]>
    </programlisting>
   </example>
  </para>
 </refsect1>
 
 <refsect1 role="seealso">
  &reftitle.seealso;
  <para>
   <simplelist>
    <member><function>curl_multi_init</function></member>
    <member><function>curl_multi_select</function></member>
    <member><function>curl_exec</function></member>
   </simplelist>
  </para>
 </refsect1>
 
</refentry>

<!-- Keep this comment at the end of the file
Local variables:
mode: sgml
sgml-omittag:t
sgml-shorttag:t
sgml-minimize-attributes:nil
sgml-always-quote-attributes:t
sgml-indent-step:1
sgml-indent-data:t
indent-tabs-mode:nil
sgml-parent-document:nil
sgml-default-dtd-file:"~/.phpdoc/manual.ced"
sgml-exposed-tags:nil
sgml-local-catalogs:nil
sgml-local-ecat-files:nil
End:
vim600: syn=xml fen fdm=syntax fdl=2 si
vim: et tw=78 syn=sgml
vi: ts=1 sw=1
-->