Last active
August 28, 2022 10:45
-
-
Save Grendel7/84f120fccd93b050621f7c7b47ee7666 to your computer and use it in GitHub Desktop.
PHP script to help identify high folders using many inodes
This file contains 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 | |
set_time_limit(0); | |
$directory = new RecursiveDirectoryIterator('../'); | |
$counters = []; | |
foreach ($directory as $item) { | |
if (!is_dir($item)) { | |
continue; | |
} | |
$parts = explode('/', $item); | |
$basename = end($parts); | |
if (strpos($basename, '.') === 0) { | |
continue; | |
} | |
$itemIterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($item)); | |
$counters[(string) $item] = iterator_count($itemIterator); | |
} | |
arsort($counters); | |
foreach ($counters as $path => $count) { | |
echo $path.': '.$count.'<br/>'.PHP_EOL; | |
} | |
echo "Total: ".array_sum($counters); |
Yep, that's right, it's a symlink in cPanel and I resolved my issue by simply dividing the total by 2 as I just wanted to receive the total only by email with a cron. Many thanks for your help!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Are
public_html
andwww
perhaps the same folder? linked with a symlink? I know cPanel does that, and it would explain the identical file count.I suppose it would be possible to folder out symlinks somehow, perhaps by tweaking the
FilesystemIterator::FOLLOW_SYMLINKS
flag on theRecursiveDirectoryIterator
.