【问题标题】:Performance comparison of ZipArchive and PharData PHP classZipArchive 和 PharData PHP 类的性能比较
【发布时间】:2014-06-03 00:19:03
【问题描述】:

由于 TAR 只是一个存档,我认为如果我使用 PharData(创建 tar 文件)代替 ZipArchive(创建 zip 文件)类,我可以获得更快的性能。

以下是我的 TAR 创建步骤。

$zip = new PharData("file.tar");

foreach ($valid_files as $file) 

{

$zip->addFile($file, str_replace('/', '', strrchr($file, '/')));

}


The Zip creation step is given below

$zip = new ZipArchive();

if($zip->open("file.zip",$overwrite ? ZIPARCHIVE::OVERWRITE : ZIPARCHIVE::CREATE) !== true) {

return "zip open failed. Exiting<br/>";

}

foreach($valid_files as $file) {

$zip->addFile($file,str_replace('/', '', strrchr($file, '/')));

}

$zip->close();

有人知道为什么创建 TAR 比创建 zip 慢吗?两者的输入都是 JPEG 文件。

【问题讨论】:

  • 假设:Ram 可以比 HDD 访问更快。如果压缩有效且快速,则存储压缩文件的整个过程可以比普通文件更快。

标签: php performance zip tar ziparchive


【解决方案1】:

找出执行每个代码需要多少时间。因此我们可以确定哪个更快。

$time_start = microtime(true); 

//Zip/Tar creation code

$time_end = microtime(true);

// calculate execution time in seconds
$execution_time = ($time_end - $time_start);

//execution time of the script
echo '<b>Total Execution Time:</b> '.$execution_time.' Seconds';

【讨论】:

  • 感谢您的回答。我已经发现 ZipArchive 比 PharData 执行得更好。但这就是问题所在。 Tar-ing 应该比 zip-ing 更快。
猜你喜欢
  • 2010-12-27
  • 2011-06-10
  • 2010-11-14
  • 2012-03-29
  • 2015-05-22
  • 2019-02-05
  • 1970-01-01
  • 1970-01-01
  • 2012-02-14
相关资源
最近更新 更多