I want to retrieve the first 10k bytes from a URL with curl (using PHP in my case). Is there a way to specify this? I thought CURLOPT_BUFFERSIZE would do this, but it just a
$html='';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_BUFFERSIZE, 128);
curl_setopt($ch, CURLOPT_NOPROGRESS, false);
curl_setopt($ch, CURLOPT_PROGRESSFUNCTION, function($DownloadSize, $Downloaded, $UploadSize, $Uploaded){ return ($Downloaded > 10240) ? 1 : 0;});
curl_setopt($ch, CURLOPT_WRITEFUNCTION, 'write_function');
curl_exec($ch);
curl_close($ch);
echo $html;
function write_function($handle, $data) {
global $html;
$html .= $data;
if (strlen($html) > 10240) {
return 0;
}
else
return strlen($data);
}