PHP服务器端增量计数器 [英] PHP server side incremental counter

查看:147
本文介绍了PHP服务器端增量计数器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对不起我是新的PHP,需要一些帮助/指导创建一个计数器,将工作服务器端,所以我想更新一个初始值?

sorry I am new to PHP and need some help/guidance on creating a counter that will work server side, so I guess update an initial value?

例如以基数1500开始,并且该数字每2分钟增加1,显然因此每次访问时任何访问者将看到增加的数目。

I need for example to start with a base number of 1500 and have that number increase by 1 every 2 minutes, obviously so any visitors will see an increased number each time the visit.

初始值需要存储在sql还是可以更新txt文件?

Would the initial value need to be stored in sql or can a txt file be updated?

任何帮助都会很好,

感谢

推荐答案

如果您不需要专门存储某些原因,运行cron等...获取您想要开始的特定时间点的时间戳。然后计算分钟,并将其添加到您的开始号码(1500)

If you don't need to store it specifically for some reason, then you don't need to run cron etc... Take a time stamp of a specific point in time you want to start at. Then calculate minutes since and add it to your start number (1500)

//Start Number
$n = 1500;
$cur_time = time();
$orig_time = strtotime("2013-10-21 10:00:00");

//New Number + difference in minutes (120 seconds for 2 mins) since start time
$newn = $n + round(abs($cur_time - $orig_time) / 120,0);

// Output New Number
echo $newn;

如果您希望在一行中进行复制/粘贴

And if you wanted it in one line for copy/paste

 echo 1500 + round(abs(time() - strtotime("2013-10-21 10:00:00")) / 120,0);

这篇关于PHP服务器端增量计数器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆