array ( 0 => 'index.php', 1 => 'PHP Manual', ), 'head' => array ( 0 => 'UTF-8', 1 => 'en', ), 'this' => array ( 0 => 'curl.examples-basic.php', 1 => 'Basic curl example', ), 'up' => array ( 0 => 'curl.examples.php', 1 => 'Examples', ), 'prev' => array ( 0 => 'curl.examples.php', 1 => 'Examples', ), 'next' => array ( 0 => 'ref.curl.php', 1 => 'cURL Functions', ), 'alternatives' => array ( ), 'source' => array ( 'lang' => 'en', 'path' => 'reference/curl/examples.xml', ), ); $setup["toc"] = $TOC; $setup["toc_deprecated"] = $TOC_DEPRECATED; $setup["parents"] = $PARENTS; manual_setup($setup); ?>
Once you've compiled PHP with cURL support, you can begin using the cURL functions. The basic idea behind the cURL functions is that you initialize a cURL session using the curl_init(), then you can set all your options for the transfer via the curl_setopt(), then you can execute the session with the curl_exec() and then you finish off your session using the curl_close(). Here is an example that uses the cURL functions to fetch the example.com homepage into a file:
Example #1 Using PHP's cURL module to fetch the example.com homepage
<?php
$ch = curl_init("http://www.example.com/");
$fp = fopen("example_homepage.txt", "w");
curl_setopt($ch, CURLOPT_FILE, $fp);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_exec($ch);
if(curl_error($ch)) {
fwrite($fp, curl_error($ch));
}
curl_close($ch);
fclose($fp);
?>