如何使用cURL使用stream_notification_callback

Max*_*ime 5 php curl

是否可以将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)

......但我的问题是如何调整这两个代码?提前致谢.

Art*_*cto 1

恐怕您的选择是要么不使用curl(并使用更有限的HTTP包装器甚至套接字)或升级。

PHP 5.2 已死(没有更多更新,甚至安全修复)。您还可以尝试为 PHP 5.2 编译 PHP 5.3(可能只有一些简单的问题),甚至向后移植支持CURLOPT_PROGRESSFUNCTION