最近私が考えている問題があります。PHPの時間と相違
私は、クライアントがPHPスクリプトを実行していなくても常に実行される2分のカウントダウンタイマーを作成する方法を理解しようとしています。 (ページに接続しているクライアントが、22秒後にそれを提示すると、それが終了すると、2分にリセットされます)。
私はtime()を登録するタイムスタンプを作成し、実際の時刻と再フォーマットされたターゲット時刻の差を計算することを考えていました。しかし、私は別の問題を思いついて、どのようにPHPスクリプトは2分ごとにそれをリセットするか知っていますか?
私はこれを解決する方法について考えていないかもしれませんが、多分解決策はありませんが、私は私を助けることができるいくつかのアイデアを見たいと思っています!
ありがとうございます!
<?php
/* A countdown timer of 2 minutes would be set from a specific time in anytime time I'd set ($timestamp), it should be able to reset everytime it reaches 0 or negative, it'd be synchronized to all users connected (everyone would see the same)*/
function generate_newtimestamp()
{
}
$timestamp = mktime(21, 43, 0, 4, 19, 2017); //(hour,minute,second,month,day,year) say this variable would start off 2 minutes ahead of current time at any time that was set, and this variable needs to self_update once 2 minutes pass (maybe server-sided...Any ideas?)
$today = time();
// now I want to calculate the difference between the actual time itself and the 2 minutes target time I want it to run
if(!negativeTimestamp($timestamp, $today))
{
$difference =($timestamp-$today);
$minutes = floor($difference/60);
$sec = ($difference/60 - $minutes) * 60;
echo $minutes . "<br>";
echo $sec;
}else{
generate_newtimestamp();
}
function negativeTimestamp($time, $stamp)
{
$difference =($stamp-$time);
return ($stamp-$time<$difference) ? true : false;
}
?>
何を試しましたか、コードを教えてください。 – Script47
クライアントがページを「セッション」にロードする時間を格納します。次の負荷で時間を比較する。 – chris85
[so]では、自分でコードを書くことができます**。 ** [もっと研究をして](// meta.stackoverflow.com/questions/261592)**あなたが問題を抱えていると、あなたが試みたものを投稿することができます** (** stackoverflow.com/help/mcve)を提供しています。私は良い質問と[完璧な質問]を読むことをお勧めします(http://codeblog.jonskeet.uk/2010/08/29/writing-the-perfect-question/)。また、[ツアー]を取って** [this](// meta.stackoverflow.com/questions/347937/)**を必ず読んでください。 –