Home > Article > Backend Development > PHP test hard disk write rate_PHP tutorial
Use php to write a 1GB file and check the writing rate of the hard disk. There may be certain errors,
It is recommended to use professional hard drive testing tools
General computers read and write at 20M/s, this test takes about 40-50s
set_time_limit(0);
$str = str_pad($str, 512, "0");
$file = fopen("./temp","a+");
$i = 0;
$bytes = 1000000000;
$mygabyte = $bytes/1000000;
echo "test start. waiting ...";
$starttime = time();
while($i < $bytes){
$i += fwrite($file, $str);
}
$endtime = time();
$usetime = $endtime - $starttime;
$write_xiaolv = $bytes/$usetime;
$myga_xiaolv = $mygabyte/$usetime;
echo "create 1GB file use time ".$usetime." secondsn";
echo "speed :".$write_xiaolv." byte/sn";
echo "speed :".$myga_xiaolv." m/sn";