Home >Backend Development >PHP Tutorial >PHP detects the running ability of the server_PHP tutorial
php detects the server’s operating capabilities
//Detection function support
function isfun($funName) {
return (false !== function_exists($funName))?'Supported':'Not supported';
}
//Integer operation ability test
function test_int() {
$timeStart = gettimeofday();
for($i = 0; $i < 3000000; $i++) {
$t = 1+1;
}
$timeEnd = gettimeofday();
$time = ($timeEnd["usec"]-$timeStart["usec"])/1000000+$timeEnd["sec"]-$timeStart["sec"];
$time = round($time, 3)."seconds";
return $time;
}
//Floating point computing capability test
function test_float() {
//Get the pi value
$t = pi();
$timeStart = gettimeofday();
for($i = 0; $i < 3000000; $i++) {
//Square root
sqrt($t);
}
$timeEnd = gettimeofday();
$time = ($timeEnd["usec"]-$timeStart["usec"])/1000000+$timeEnd["sec"]-$timeStart["sec"];
$time = round($time, 3)."seconds";
return $time;
}
//IO ability test
function test_io() {
$fp = @fopen(PHPSELF, "r");
$timeStart = gettimeofday();
for($i = 0; $i < 10000; $i++) {
@fread($fp, 10240);
@rewind($fp);
}
$timeEnd = gettimeofday();
@fclose($fp);
$time = ($timeEnd["usec"]-$timeStart["usec"])/1000000+$timeEnd["sec"]-$timeStart["sec"];
$time = round($time, 3)."seconds";
return($time);
}