计算不同页面php上的时间处理


Calculate time processing on different page php

我在的第一页上尝试了这个代码

$time_start = microtime(true);
$_SESSION['varname'] = $time_start;

这个代码在第二页

$time_start = $_SESSION['varname'];
$time_end = microtime(true);
$time = $time_end - $time_start;
  echo 'Execution time : '.$time.' seconds';

但变量$time_start未知如何计算不同页面上的时间处理?

试试这个。。

test1.php

session_start();
$time_start = microtime(true);
$_SESSION['varname'] = $time_start;

test2.php

session_start();
$time_start = $_SESSION['varname'];
$time_end = microtime(true);
$time = $time_end - $time_start;
echo 'Execution time : ' . $time . ' seconds';

输出:执行时间:77.626733064651秒