Php 如何在指定时间自动重新加载或刷新网页?

Php 如何在指定时间自动重新加载或刷新网页?,php,time,Php,Time,我正在使用API。问题是这个API每60秒给出一次结果。其程序设定为每分钟06秒后交付结果。 那就是00:06(MM:SS),01:06,02:06等等 我想有2秒的空白,所以我想刷新我的页面在08秒粘贴每分钟 我不是一个程序员,但正在学习,下面的解决方案非常适合我使用,但我想这不是正确的方法吗 是否有其他较短的方法可以实现此代码的结果: <?php $nowis = date('s'); if ( $nowis == "00" ) {$reload = "08" ;} if ( $

我正在使用API。问题是这个API每60秒给出一次结果。其程序设定为每分钟06秒后交付结果。 那就是00:06(MM:SS),01:06,02:06等等

我想有2秒的空白,所以我想刷新我的页面在08秒粘贴每分钟

我不是一个程序员,但正在学习,下面的解决方案非常适合我使用,但我想这不是正确的方法吗

是否有其他较短的方法可以实现此代码的结果:

<?php

$nowis = date('s');

if ( $nowis == "00" ) {$reload = "08" ;} 
if ( $nowis == "01" ) {$reload = "07" ;} 
if ( $nowis == "02" ) {$reload = "06" ;} 
if ( $nowis == "03" ) {$reload = "05" ;} 
if ( $nowis == "04" ) {$reload = "04" ;} 
if ( $nowis == "05" ) {$reload = "03" ;} 
if ( $nowis == "06" ) {$reload = "62" ;} 
if ( $nowis == "07" ) {$reload = "61" ;} 
if ( $nowis == "08" ) {$reload = "60" ;} 
if ( $nowis == "09" ) {$reload = "59" ;} 
if ( $nowis == "10" ) {$reload = "58" ;} 
if ( $nowis == "11" ) {$reload = "57" ;} 
if ( $nowis == "12" ) {$reload = "56" ;} 
if ( $nowis == "13" ) {$reload = "55" ;} 
if ( $nowis == "14" ) {$reload = "54" ;} 
if ( $nowis == "15" ) {$reload = "53" ;} 
if ( $nowis == "16" ) {$reload = "52" ;} 
if ( $nowis == "17" ) {$reload = "51" ;} 
if ( $nowis == "18" ) {$reload = "50" ;} 
if ( $nowis == "19" ) {$reload = "49" ;} 
if ( $nowis == "20" ) {$reload = "48" ;} 
if ( $nowis == "21" ) {$reload = "47" ;} 
if ( $nowis == "22" ) {$reload = "46" ;} 
if ( $nowis == "23" ) {$reload = "45" ;} 
if ( $nowis == "24" ) {$reload = "44" ;} 
if ( $nowis == "25" ) {$reload = "43" ;} 
if ( $nowis == "26" ) {$reload = "42" ;} 
if ( $nowis == "27" ) {$reload = "41" ;} 
if ( $nowis == "28" ) {$reload = "40" ;} 
if ( $nowis == "29" ) {$reload = "39" ;} 
if ( $nowis == "30" ) {$reload = "38" ;} 
if ( $nowis == "31" ) {$reload = "37" ;} 
if ( $nowis == "32" ) {$reload = "36" ;} 
if ( $nowis == "33" ) {$reload = "35" ;} 
if ( $nowis == "34" ) {$reload = "34" ;} 
if ( $nowis == "35" ) {$reload = "33" ;} 
if ( $nowis == "36" ) {$reload = "32" ;} 
if ( $nowis == "37" ) {$reload = "31" ;} 
if ( $nowis == "38" ) {$reload = "30" ;} 
if ( $nowis == "39" ) {$reload = "29" ;} 
if ( $nowis == "40" ) {$reload = "28" ;} 
if ( $nowis == "41" ) {$reload = "27" ;} 
if ( $nowis == "42" ) {$reload = "26" ;} 
if ( $nowis == "43" ) {$reload = "25" ;} 
if ( $nowis == "44" ) {$reload = "24" ;} 
if ( $nowis == "45" ) {$reload = "23" ;} 
if ( $nowis == "46" ) {$reload = "22" ;} 
if ( $nowis == "47" ) {$reload = "21" ;} 
if ( $nowis == "48" ) {$reload = "20" ;} 
if ( $nowis == "49" ) {$reload = "19" ;} 
if ( $nowis == "50" ) {$reload = "18" ;} 
if ( $nowis == "51" ) {$reload = "17" ;} 
if ( $nowis == "52" ) {$reload = "16" ;} 
if ( $nowis == "53" ) {$reload = "15" ;} 
if ( $nowis == "54" ) {$reload = "14" ;} 
if ( $nowis == "55" ) {$reload = "13" ;} 
if ( $nowis == "56" ) {$reload = "12" ;} 
if ( $nowis == "57" ) {$reload = "11" ;} 
if ( $nowis == "58" ) {$reload = "10" ;} 
if ( $nowis == "59" ) {$reload = "09" ;} 

echo $nowis;
echo " - ";
echo $reload;

?>

<meta http-equiv="refresh" content="<?php echo $reload; ?>" >

这个怎么样

只是一些数学,而不是
if

<?php
$nowis = date('s');
$reload = (8 - $nowis + 60) % 60;
echo $nowis;
echo " - ";
echo $reload;
?>
<meta http-equiv="refresh" content="<?php echo $reload; ?>" >


此代码应该可以帮助您:

$now = date('s');
$reload = (8 - $now) %  60;
header("refresh: $reload; url=page.php");

使用javascript的计时器:

// refresh 60 seconds later, only once,
var timeoutId = setTimeout(new function(){location.reload() }, 60 * 1000);

// clear the setTimeout, so that it won't refresh if not yet,
clearTimeout(timeoutId);

// refresh every 20 seconds, repeatly,
var intervalId = setInterval(new function(){location.reload() }, 20 * 1000)

// clear the setInterval, so that it will stop refresh frequently,
window.clearInterval(intervalId)

我建议使用JavaScript,甚至AJAX,这取决于你想刷新多少D@OzanKurt在这种情况下,您可以在.properties文件中配置间隔,并通过php加载,通过json发送到客户端,这样javascript也可以读取它,然后javascript可以根据参数进行控制,php能够修改属性。顺便说一句,我认为提问者可以更加灵活,只使用一种方式或一种语言并不真正有益。我认为你是对的。但是如果他/她不太懂js呢?@OzanKurt如果他/她在做网络编程。。。javascript是非常必要的,会很有帮助,^^是的,js让事情变得更简单。我还建议您查看jQuery。