Is it possible to use stream_notification_callback with cURL?
I would like to adapt example # 1, which I found here http://www.php.net/manual/en/function.stream-notification-callback.php , to my cURL function below, to create / update a text file that contains loaded bytes.
I know what is CURLOPT_PROGRESSFUNCTIONimplemented in php 5.3, but I am running php 5.2 and I can’t upgrade.
private function Save($url) {
$this->SetTempFileName(time());
$file = fopen($this->GetTempVidFileName(), 'w');
$ckfile = tempnam("/tmp_cookie", "CURLCOOKIE");
$ch = curl_init();
curl_setopt($ch, CURLOPT_FILE, $file);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_COOKIEFILE, $ckfile);
curl_setopt($ch, CURLOPT_COOKIEJAR, $ckfile);
curl_exec($ch);
curl_close($ch);
fclose($file);
return is_file($this->GetTempFileName());
}
I know that I will have to use file_put_contents to replace the case STREAM_NOTIFY_PROGRESS part like this ...
case STREAM_NOTIFY_PROGRESS:
file_put_contents('progress.txt', $bytes_transferred);
break;
... but my question is how to adapt two codes? Thanks in advance.
source
share