Created
September 3, 2019 21:39
-
-
Save unique1984/41edf705869ea935f4398a92653fb5c5 to your computer and use it in GitHub Desktop.
Create 500 folder and each one nested 1000 files and destroy them with php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
mkdir hugeNumberOfFiles | |
for i in `seq 500`; do mkdir hugeNumberOfFiles/$i; for j in `seq 1000`; do touch hugeNumberOfFiles/$i/$j.txt; done; done | |
for i in `seq 4`; do cp -r hugeNumberOfFiles hugeNumberOfFiles$i; done | |
# hugeNumberOfFiles -> 500 folders and nested total 500000 files |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$total_start = microtime(true); | |
function rrmdir($dir) | |
{ | |
if (is_dir($dir)) { | |
$objects = scandir($dir); | |
foreach ($objects as $object) { | |
if ($object != "." && $object != "..") { | |
if (filetype($dir . "/" . $object) == "dir") { | |
rrmdir($dir . "/" . $object); | |
} else { | |
unlink($dir . "/" . $object); | |
} | |
} | |
} | |
reset($objects); | |
rmdir($dir); | |
} | |
} | |
function rrmdirDI($path) { | |
// Remove a dir (all files and folders in it) | |
$i = new DirectoryIterator($path); | |
foreach($i as $f) { | |
if($f->isFile()) { | |
unlink($f->getRealPath()); | |
} | |
else if(!$f->isDot() && $f->isDir()) { | |
rrmdirDI($f->getRealPath()); | |
rmdir($f->getRealPath()); | |
} | |
} | |
} | |
$start = microtime(true); | |
exec('rm -rf hugeNumberOfFiles4'); | |
echo "exec " . (microtime(true) - $start) . " sn\n"; | |
$start = microtime(true); | |
shell_exec('rm -rf hugeNumberOfFiles3'); | |
echo "shell_exec " . (microtime(true) - $start) . " sn\n"; | |
$start = microtime(true); | |
rrmdir('hugeNumberOfFiles2'); | |
echo "rrmdir [scandir] " . (microtime(true) - $start) . " sn\n"; | |
$start = microtime(true); | |
rrmdirDI('hugeNumberOfFiles1'); | |
echo "rrmdirDI [DirectoryIterator] " . (microtime(true) - $start) . " sn\n\n"; | |
echo "Toplam süre: " . (microtime(true) - $total_start) . " sn\n"; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Son olarak: