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);
        }
    }
}



Sign up now


I agree with your conditions


↑ Skip to TOP ↑