是否可以将stream_notification_callback与cURL一起使用?
我想调整我在http://www.php.net/manual/en/function.stream-notification-callback.php找到的示例#1 到我下面的cURL函数来创建/更新文本文件包含下载的字节.
我知道这CURLOPT_PROGRESSFUNCTION
是在PHP 5.3中实现但我运行PHP 5.2我无法升级.
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());
}
Run Code Online (Sandbox Code Playgroud)
我知道我必须使用file_put_contents来替换像这样的"case STREAM_NOTIFY_PROGRESS"部分......
case STREAM_NOTIFY_PROGRESS:
file_put_contents('progress.txt', $bytes_transferred);
break;
Run Code Online (Sandbox Code Playgroud)
......但我的问题是如何调整这两个代码?提前致谢.