日期();即使php中有事件,也会返回相同的时间


Date(); returning same time even with an event in php

还有其他方法可以做到这一点吗?因为$timestart和$timestop都会给我相同的结果,即使两者之间有一个事件。

<?php 
$timestart = strtotime(date('H:i:s', time()));
if(isset($_POST['choix186']) ){
    $timestop = strtotime(date('H:i:s', time()));
    $duree = $timestop - $timestart;
    }
print $duree"; 
?>

"标准"计时器脚本是这样的:

示例#1使用microtime()计时脚本执行

$time_start = microtime_float();
// Sleep for a while
usleep(100);
$time_end = microtime_float();
$time = $time_end - $time_start;
echo "Did nothing in $time seconds'n";
?>

示例#2 PHP 5 中定时脚本执行

<?php
$time_start = microtime(true);
// Sleep for a while
usleep(100);
$time_end = microtime(true);
$time = $time_end - $time_start;
echo "Did nothing in $time seconds'n";
?>

示例#3 microtime()和REQUEST_TIME_FLOAT(从PHP 5.4.0开始)

<?php
// Randomize sleeping time
usleep(mt_rand(100, 10000));
// As of PHP 5.4.0, REQUEST_TIME_FLOAT is available in the $_SERVER superglobal array.
// It contains the timestamp of the start of the request with microsecond precision.
$time = microtime(true) - $_SERVER["REQUEST_TIME_FLOAT"];
echo "Did nothing in $time seconds'n";
?>

来源:http://php.net/manual/en/function.microtime.php

无需添加,手动了解所有