I'm trying to read just one chunk of a stream of data using curl.
Ideally I would like to just retreive the first image in the stream and write that to a jpg file.
I'm attempting to do this using WRITEFUNCTION and returning -1 if the length of the stream > say 20000.
function receiveResponse($ch,$string) {
$length = strlen($string);
if($length >= 20000) { return -1; }
return $length;
}
$ch = curl_init('http://<url>/videostream.cgi');
curl_setopt($ch, CURLOPT_USERPWD, '<user>:<password>');
curl_setopt($ch, CURLOPT_WRITEFUNCTION, "receiveResponse");
curl_setopt($ch, CURLOPT_FILE, $fh);
curl_exec($ch);
However the stream just continues to write to the file which ends up getting larger and larger in file size.
How can I fix it?