fwrite($path, $str, $sort='0') {
$filestr = file($path);
$total = count($filestr);
$strf = '';
for ($i = 0; $i < $total; ++$i)
{
$strf .= $filestr[$i];
}
if(!$sort)
$str = "{$strf}n{$str}";
else
$str = "{$str}n{$strf}";
$f = fopen($path, 'a+');
if(flock($f, LOCK_EX))
{
ftruncate($f, 0);
fputs($f, $str);
fflush($f);
flock($f, LOCK_UN);
fclose($f);
}
}