API – Part 1
When you have scripts to read, write filesystems from or to machine and could go countless, it is always best to manage the directory structure nested and each sub tree go recursively nested to accomadate at that level. The benefit is that it helps in not also specific lookup, but precise write up and added broader search. We appreciate performance boost also by this structure of nested files – directory structure.
$type = type of user identifier
$handle = some seed sort, say
///////////////// handle the logic as below ///////////////////////////
$handle = strtolower($handle);
$hash = 0;
for($i=0; $i < strlen($handle) ; $i++)
{
$value = substr($handle, $i, 1);
$hash = $hash*23 + ord($value);
$hash %= 8000;
}
$home=”";
if ($type ==”user”)
{
$home .=SERVER_PATH.(1+($hash % 8));
}
$hash >>=3;
$hash %=1000;
if ($type ==”user”)
{
$home .= “/$hash/$handle”;
}
else
{
$home .= “/$hash/”;
}
return $home;
} # end function.
///////////////////////////////////////////////////////////////////////////
Loading...