
正文
php每隔几分钟检测数据,php每隔几分钟检测数据不一样
提示:扫一扫查出行【扫一扫了解最新限行尾号】
复制提示
PHP如何每隔一段时间取一段数据?
你要用什麼来做?可以开一个shell来执行一个永远循环的php脚本,也可以用js触发,也可以用crontab来执行
相关问答
Q1: 使用PHP如何做到每隔5分钟的时间,首页会向服务器轮询一次,以便获得最新的数据。
用js的setInterval写一个定时器,每隔5分钟,使用ajax请求一次数据,
Q2: php能不能每隔一段时间插入一条数据
可以,第一种:可以在服务器上写一个定时任务,每隔一段时间调用一个插入数据接口。
第二种:foreach里面写sleep(1);暂停
Q3: php 每隔5分钟输出数组中的一部分
这个用写文件的方式保留初始时间,等循环一次之后再重置
$file="a.txt";
if(!file_exists($file))
{
$handle=fopen('a.txt','w');
fwrite($handle,time());
fclose($handle);
}
$start=file_get_contents($file);
$time=time();
$text = array('a','b','c','d','e');
$index=0;
$dif=$time-$start;
if($dif5*60 and $dif10*60)
{
$index=1;
}
elseif($dif10*60 and $dif15*60)
{
$index=2;
}
elseif($dif15*60 and $dif20*60)
{
$index=3;
}
elseif($dif20*60 and $dif25*60)
{
$index=4;
}
elseif($dif25*60)
{
$handle=fopen('a.txt','w');
fwrite($handle,time());
fclose($handle);
$index=0;
}
echo $text[$index];







