Example #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;
Example #2
0
function read_directory()
{
	global $php_errormsg;
	
	if(empty($_SESSION['DIR'])) $_SESSION['DIR']=abs_path(HOMEDIR);
	
	if(!empty($_REQUEST['DIR']) && $_REQUEST['DIR'][0]=='~') $_REQUEST['DIR']=HOMEDIR.substr($_REQUEST['DIR'],1);
	if(!empty($_REQUEST['DIR']) && $_REQUEST['DIR'] == '.' && !empty($_SESSION['DIR'])) $_REQUEST['DIR']=$_SESSION['DIR']; // especially to save current directory state with refreshes in full version

	$dir=!empty($_REQUEST['dir']) ? clean($_SESSION['DIR'].'/'.$_REQUEST['dir'],true) : $_SESSION['DIR'];
	if(!empty($_REQUEST['DIR'])) $dir=clean($_REQUEST['DIR'],true);
	else $_REQUEST['DIR']=HOMEDIR;
	
	//$_REQUEST['DIR']=abs_path($_REQUEST['DIR']);
	//echo $_REQUEST['DIR'];
	
	
	$c = lang('My computer');
	
	$r = $_REQUEST['DIR'];
	$l = strlen($r);
	
	if(getenv('COMSPEC') &&  ($l==5 || $l==6) && substr($r,-2)=='..' /* A:/.. || A://.. */ && (abs_path($r)) == substr($r,0,2).'/') $_REQUEST['DIR'] = $c;

    $dh = opendir($dir);
    if (!$dh) return d_error("Cannot open $dir");
    $_SESSION['DIR']=$dir;
    session_write_close();

    $res = d_filelist_simple($dh);
	closedir($dh);

	if(abs_path($_SESSION['DIR']) == '/') $up = false;
    else $up = dirname($_SESSION['DIR']);
	$res['up'] = $up;

    return $res;
}