Пример #1
0
if ($argc != 2) {
    fwrite(STDERR, "Usage: {$argv['0']} <variant>\n");
    exit(1);
}
$dir = "/Users/yuriy/tmp/50000";
$time = microtime(true);
$memory = memory_get_usage();
register_shutdown_function(function () use($time, $memory) {
    fwrite(STDERR, "Done in " . round((microtime(true) - $time) * 1000) . "ms\n");
    fwrite(STDERR, "Memory usage: " . round((memory_get_peak_usage() - $memory) / 1024 / 1024, 2) . " Mb\n");
    fwrite(STDERR, "Overall memory usage: " . round(memory_get_peak_usage() / 1024 / 1024, 2) . " Mb\n");
});
switch ($argv[1]) {
    default:
        fwrite(STDERR, "Unknown variant '{$argv['1']}': valid options are 1-4\n");
        exit(1);
    case 1:
        $result = d_filelist_fast($dir);
        break;
    case 2:
        $result = d_filelist_extreme($dir, array('perpage' => 1000));
        break;
    case 3:
        $result = d_filelist_cached($dir, 0, 1000);
        break;
    case 4:
        $result = d_filelist_simple($dir);
        break;
}
$json = json_encode($result);
echo $json;
Пример #2
0
function d_filesize($f)
{
	if(file_exists($f) && ($sz = filesize($f))!==false) return ($sz>=0 ? $sz : sprintf("%u", $sz)); // damn PHP bug with filesizes > 2Gb and <= 4 Gb... If the filesize is even greater, only 64bit compilations of PHP should give correct result
	$f = abs_path($f);
	
	$t = d_filelist_fast(dirname($f));
	
	if(!empty($t['fsizes'][$f])) return $t['fsizes'][$f];
	
	return false;
}