<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> <title>Perform a cURL session</title> </head> <body><div class="manualnavbar" style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="function.curl-escape.html">curl_escape</a></div> <div class="next" style="text-align: right; float: right;"><a href="function.curl-file-create.html">curl_file_create</a></div> <div class="up"><a href="ref.curl.html">cURL Functions</a></div> <div class="home"><a href="index.html">PHP Manual</a></div> </div><hr /><div id="function.curl-exec" class="refentry"> <div class="refnamediv"> <h1 class="refname">curl_exec</h1> <p class="verinfo">(PHP 4 >= 4.0.2, PHP 5)</p><p class="refpurpose"><span class="refname">curl_exec</span> — <span class="dc-title">Perform a cURL session</span></p> </div> <div class="refsect1 description" id="refsect1-function.curl-exec-description"> <h3 class="title">Description</h3> <div class="methodsynopsis dc-description"> <span class="type"><a href="language.pseudo-types.html#language.types.mixed" class="type mixed">mixed</a></span> <span class="methodname"><strong>curl_exec</strong></span> ( <span class="methodparam"><span class="type">resource</span> <code class="parameter">$ch</code></span> )</div> <p class="para rdfs-comment"> Execute the given cURL session. </p> <p class="para"> This function should be called after initializing a cURL session and all the options for the session are set. </p> </div> <div class="refsect1 parameters" id="refsect1-function.curl-exec-parameters"> <h3 class="title">Parameters</h3> <p class="para"> <dl> <dt> <span class="term"><em><code class="parameter">ch</code></em> </span><dd> <p class="para">A cURL handle returned by <span class="function"><a href="function.curl-init.html" class="function">curl_init()</a></span>.</p></dd> </dt> </dl> </p> </div> <div class="refsect1 returnvalues" id="refsect1-function.curl-exec-returnvalues"> <h3 class="title">Return Values</h3> <p class="para"> Returns <strong><code>TRUE</code></strong> on success or <strong><code>FALSE</code></strong> on failure. However, if the <strong><code>CURLOPT_RETURNTRANSFER</code></strong> option is <a href="function.curl-setopt.html" class="link">set</a>, it will return the result on success, <strong><code>FALSE</code></strong> on failure. </p> </div> <div class="refsect1 examples" id="refsect1-function.curl-exec-examples"> <h3 class="title">Examples</h3> <p class="para"> <div class="example" id="example-4213"> <p><strong>Example #1 Fetching a web page</strong></p> <div class="example-contents"> <div class="phpcode"><code><span style="color: #000000"> <span style="color: #0000BB"><?php<br /></span><span style="color: #FF8000">// create a new cURL resource<br /></span><span style="color: #0000BB">$ch </span><span style="color: #007700">= </span><span style="color: #0000BB">curl_init</span><span style="color: #007700">();<br /><br /></span><span style="color: #FF8000">// set URL and other appropriate options<br /></span><span style="color: #0000BB">curl_setopt</span><span style="color: #007700">(</span><span style="color: #0000BB">$ch</span><span style="color: #007700">, </span><span style="color: #0000BB">CURLOPT_URL</span><span style="color: #007700">, </span><span style="color: #DD0000">"http://www.example.com/"</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">curl_setopt</span><span style="color: #007700">(</span><span style="color: #0000BB">$ch</span><span style="color: #007700">, </span><span style="color: #0000BB">CURLOPT_HEADER</span><span style="color: #007700">, </span><span style="color: #0000BB">0</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">// grab URL and pass it to the browser<br /></span><span style="color: #0000BB">curl_exec</span><span style="color: #007700">(</span><span style="color: #0000BB">$ch</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">// close cURL resource, and free up system resources<br /></span><span style="color: #0000BB">curl_close</span><span style="color: #007700">(</span><span style="color: #0000BB">$ch</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?></span> </span> </code></div> </div> </div> </p> </div> <div class="refsect1 seealso" id="refsect1-function.curl-exec-seealso"> <h3 class="title">See Also</h3> <p class="para"> <ul class="simplelist"> <li class="member"> <span class="function"><a href="function.curl-multi-exec.html" class="function" rel="rdfs-seeAlso">curl_multi_exec()</a> - Run the sub-connections of the current cURL handle</span></li> </ul> </p> </div> </div><hr /><div class="manualnavbar" style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="function.curl-escape.html">curl_escape</a></div> <div class="next" style="text-align: right; float: right;"><a href="function.curl-file-create.html">curl_file_create</a></div> <div class="up"><a href="ref.curl.html">cURL Functions</a></div> <div class="home"><a href="index.html">PHP Manual</a></div> </div></body></html>