<?php
// Init curl session
$ch = curl_init();
// Set URL
curl_setopt($ch, CURLOPT_URL, "http://www.php.net/");
// Set callback function for headers
curl_setopt($ch, CURLOPT_HEADERFUNCTION, "read_header");
// Set callback function for body
curl_setopt($ch, CURLOPT_WRITEFUNCTION, "read_body");
// Execute curl
curl_exec($ch);
// close curl session
curl_close($ch);
// Callback function for header
function read_header($ch, $string) {
$length = strlen($string);
echo "Header: $string\n";
return $length;
}
// Callback function for body
function read_body($ch, $string) {
curl_close($ch);
$length = strlen($string);
echo "Received $length bytes\n";
return $length;
}
?>