Wait for full page load
logo
logo
logo
logo
logo
logo
logo
logo
logo
logo
logo

PHP - delete huge directory


Advertisements
PHP - delete huge directory PHP is huge helper on Linux systems. You have probably tried to find multiple solutions to delete large directory, created usually by automatic script (temp directory etc). Hereby we are publishing a solution, which can easily delete directory of nearly unlimited files inside. This solution delete files slowly, pausing itself for 3 seconds, where server load is higher than 6 (you can change it anytime). We use this tool pretty often, since it does not hang our heavy-load servers. #!/usr/bin/php

Sign up now


I agree with your conditions

PHP - delete huge directory

PHP is huge helper on Linux systems. You have probably tried to find multiple solutions to delete large directory, created usually by automatic script (temp directory etc). Hereby we are publishing a solution, which can easily delete directory of nearly unlimited files inside. This solution delete files slowly, pausing itself for 3 seconds, where server load is higher than 6 (you can change it anytime). We use this tool pretty often, since it does not hang our heavy-load servers.

#!/usr/bin/php

$mdir="/DIR-TO-REMOVE/";
$d = dir($mdir);
$cnt=0;
while (false !== ($entry = $d->read())) {
    $file=$mdir.$entry;
    unlink($file);
   // echo $entry."\n";
    $cnt++;
    if ($cnt>1000) {
        echo "Sleep 3\n";
        sleep(3);
        $cnt=0;
    }
    if ($cnt==100) {
        $load = sys_getloadavg();
        if ($load[0] > 6) {
            echo "Load ".$load[0].", Sleep 3\n";
            sleep(3);
        }
    }
}



From Our Blog

  1. Compare web hosting (7 months ago)
  2. Cloud hosting map (2 months ago)
  3. PHP - delete huge directory (1 months ago)
  4. 9 WooCommerce bulk product editing tools (1 months ago)
  5. Six Easy Tips for Faster Android (1 months ago)
  6. UTP cable (Unshielded Twisted Pair) (1 months ago)
  7. Cybercrime has overtaken the traditional one already in 2015! (1 months ago)
  8. Far Manager review (1 months ago)
  9. Best software for accountants 2018 (1 months ago)
  10. What to Check Before Logging In to Online Bank Account (0 months ago)
  11. MobaXterm review (0 months ago)
  12. Steps needed to change web hosting provider (0 months ago)
  13. What is TensorFlow? (0 months ago)
  14. How to move your website to SSL version (0 months ago)
  15. How do change domain name of your website (0 months ago)
  16. What is a GCLID? (18 days ago)
  17. Top projects to protect your website from bad bots (12 days ago)

Sign up now


I agree with your conditions


↑ Skip to TOP ↑