原计划是使用sleep执行,后网上看到这个方法挺不错的
通过计算时间差来处理
$now = time();
session_start();
$last = $_SESSION['lastvisit'];
if (!isset($last) || $now - $last > 45) {
$points = $_SESSION['points'];
if (!isset($points)) {
$points = 0;
}
$_SESSION['points'] = $points + 10;
$_SESSION['lastvisit'] = $now;
}