Reputation: 534
I want to pack around 10.000 files into a .tar archive using the code below. Nothing too big the size of the archive will not be more than a few 100MB. My problem is that this takes ages. Actually I am packing 9000 files for an hour now. On the shell this is done within 2 minutes, it is a powerful linux server running apache2. So what is wrong here? How can I increase the speed of the PHP script?
$Path = str_replace('\\', '/', realpath($Path));
if (is_dir($Path) === true) {
$files = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($Path), \RecursiveIteratorIterator::SELF_FIRST);
$archive = new \PharData('/var/www/test.tar');
foreach ($files as $file) {
$filePath = $file->getRealPath();
$archive->addFile($filePath);
}
Upvotes: 1
Views: 638
Reputation: 686
RecursiveIteratorIterator is quite slow... But question is why you use it? Try Phardata buildFromDirectory function:
<?php
...
if (is_dir($Path) === true) {
$archive = new PharData('/var/www/test.tar');
$archive->buildFromDirectory($Path);
}
...
?>
Hope is helps
Upvotes: 1