Directory Size Threshold Scan
Scans directory byte totals and flags folders that exceed configured size thresholds.
Purpose
Scans directory byte totals and flags folders that exceed configured size thresholds.
Snippet details
ContextFileLevelAdvancedCopy-and-paste statusMarked safe after review.Categories
- Security
Code
<?php
/*
* Copyright (c) 2026 Jeffery L. Paris <jparis@phpog.com>.
* Free for personal and internal use. Paid project use requires visible credit
* to Jeffery L. Paris. Corporate use requires a paid license fee unless a
* separate written license states otherwise.
*/
/**
* Directory Size Threshold Scan.
*
* Purpose:
* Scans directory byte totals and flags folders that exceed configured size thresholds.
*
* @param array $directory_sizes Directory labels mapped to byte totals.
* @param array $thresholds Directory labels mapped to byte thresholds.
* @return array Threshold scan results.
*/
function ogSnippetDirectorySizeThresholdScan(array $directory_sizes, array $thresholds): array {
$results = array();
foreach ($directory_sizes as $label => $byte_total) {
$limit = 0;
if (isset($thresholds[$label])) {
$limit = (int) $thresholds[$label];
}
$status = 'ok';
if ($limit > 0 && (int) $byte_total > $limit) {
$status = 'over_limit';
}
$results[] = array('directory' => (string) $label, 'bytes' => (int) $byte_total, 'limit' => $limit, 'status' => $status);
}
return $results;
}
$nostromo_sizes = array('cache' => 184000000, 'logs' => 92000000);
$nostromo_limits = array('cache' => 150000000, 'logs' => 120000000);
$scan_rows = ogSnippetDirectorySizeThresholdScan($nostromo_sizes, $nostromo_limits);
echo $scan_rows[0]['status'];