问题描述
|
您好,我的目标是修改以下脚本,以基于计时器(而不是页面访问)添加+1。
我的意思是,计时器每20分钟必须增加+1位访问者。如果可能的话,最好在15到20分钟之间的随机时间内加上+1。
然后结果将显示在页面中。这是代码
<?php
$File = \"counter.txt\"; //the file
$handle = fopen($File,\'r+\') ;
$data = fread($handle,512) ; //get the number on the counter
$count = $data + 1; //Add 1
print \"You are visitor number \".$count; //Prints it on page
fseek($handle,0) ; //puts the pointer back to the begining
fwrite($handle,$count) ; //saves it
fclose($handle) ; //close it
?>
谢谢!
解决方法
为此,您需要使脚本不作为页面请求的一部分运行,即在命令行上使用外部任务计划程序(如anacron)或使其始终运行,在延迟时间内休眠并执行循环计数。