1. <legend id='vFPns'><style id='vFPns'><dir id='vFPns'><q id='vFPns'></q></dir></style></legend>

    <small id='vFPns'></small><noframes id='vFPns'>

      <bdo id='vFPns'></bdo><ul id='vFPns'></ul>
  2. <i id='vFPns'><tr id='vFPns'><dt id='vFPns'><q id='vFPns'><span id='vFPns'><b id='vFPns'><form id='vFPns'><ins id='vFPns'></ins><ul id='vFPns'></ul><sub id='vFPns'></sub></form><legend id='vFPns'></legend><bdo id='vFPns'><pre id='vFPns'><center id='vFPns'></center></pre></bdo></b><th id='vFPns'></th></span></q></dt></tr></i><div id='vFPns'><tfoot id='vFPns'></tfoot><dl id='vFPns'><fieldset id='vFPns'></fieldset></dl></div>

  3. <tfoot id='vFPns'></tfoot>

    1. PHP服务器端定时器

      PHP server side timer(PHP服务器端定时器)

        <bdo id='qSCfV'></bdo><ul id='qSCfV'></ul>
      • <i id='qSCfV'><tr id='qSCfV'><dt id='qSCfV'><q id='qSCfV'><span id='qSCfV'><b id='qSCfV'><form id='qSCfV'><ins id='qSCfV'></ins><ul id='qSCfV'></ul><sub id='qSCfV'></sub></form><legend id='qSCfV'></legend><bdo id='qSCfV'><pre id='qSCfV'><center id='qSCfV'></center></pre></bdo></b><th id='qSCfV'></th></span></q></dt></tr></i><div id='qSCfV'><tfoot id='qSCfV'></tfoot><dl id='qSCfV'><fieldset id='qSCfV'></fieldset></dl></div>
      • <small id='qSCfV'></small><noframes id='qSCfV'>

        1. <legend id='qSCfV'><style id='qSCfV'><dir id='qSCfV'><q id='qSCfV'></q></dir></style></legend>
            • <tfoot id='qSCfV'></tfoot>

                <tbody id='qSCfV'></tbody>

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

                问题描述

                我需要制作一个带有倒计时功能的页面.我希望计时器在服务器端,这意味着当用户打开页面时,所有用户的计数器将始终处于同一时间.当计时器归零时,我需要能够运行另一个脚本,这会在重置计时器的同时执行一些操作.

                I need to make a page that has a timer counting down. I want the timer to be server side, meaning that when ever a user opens the page the counter will always be at the same time for all users. When the timer hits zero I need to be able to run another script, that does some stuff along with resetting the timer.

                我怎样才能用 php 做这样的事情?

                How would I be able to make something like this with php?

                推荐答案

                从用户何时打开页面"来看,该页面不应该有自动更新机制吗?如果这不是您的意思,请查看 AJAX(如评论中所述)或更简单的 HTML META 刷新.或者,使用 PHP 和 header()

                Judging from "when ever a user opens the page" there should not be an auto-update mechanism of the page? If this is not what you meant, look into AJAX (as mentioned in the comments) or more simply the HTML META refresh. Alternatively, use PHP and the header()

                http://de2.php.net/manual/en/function.header.php

                方法,也在这里描述:

                使用 PHP 刷新页面

                对于计数器本身,您需要保存结束日期(例如数据库或文件),然后将当前时间戳与保存的值进行比较.

                For the counter itself, you would need to save the end date (e.g. a database or a file) and then compare the current timestamp with the saved value.

                假设您的脚本文件夹中有一个包含 unix 时间戳的文件,您可以执行以下操作:

                Lets assume there is a file in the folder of your script containing a unix timestamp, you could do the following:

                <?php
                $timer = 60*5; // seconds
                $timestamp_file = 'end_timestamp.txt';
                if(!file_exists($timestamp_file))
                {
                  file_put_contents($timestamp_file, time()+$timer);
                }
                $end_timestamp = file_get_contents($timestamp_file);
                $current_timestamp = time();
                $difference = $end_timestamp - $current_timestamp;
                
                if($difference <= 0)
                {
                  echo 'time is up, BOOOOOOM';
                  // execute your function here
                  // reset timer by writing new timestamp into file
                  file_put_contents($timestamp_file, time()+$timer);
                }
                else
                {
                  echo $difference.'s left...';
                }
                ?>
                

                您可以使用http://www.unixtimestamp.com/index.php熟悉 Unix 时间戳.

                You can use http://www.unixtimestamp.com/index.php to get familiar with the Unix Timestamp.

                通向罗马的方式有很多种,这只是其中一种.

                There are many ways that lead to rome, this is just one of the simple ones.

                这篇关于PHP服务器端定时器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                相关文档推荐

                DeepL的翻译效果还是很强大的,如果我们要用php实现DeepL翻译调用,该怎么办呢?以下是代码示例,希望能够帮到需要的朋友。 在这里需要注意,这个DeepL的账户和api申请比较难,不支持中国大陆申请,需要拥有香港或者海外信用卡才行,没账号的话,目前某宝可以
                PHP通过phpspreadsheet导入Excel日期,导入系统后,全部变为了4开头的几位数字,这是为什么呢?原因很简单,将Excel的时间设置问文本,我们就能看到该日期本来的数值,上图对应的数值为: 要怎么解决呢?进行数据转换就行,这里可以封装方法,或者用第三方的
                mediatemple - can#39;t send email using codeigniter(mediatemple - 无法使用 codeigniter 发送电子邮件)
                Laravel Gmail Configuration Error(Laravel Gmail 配置错误)
                Problem with using PHPMailer for SMTP(将 PHPMailer 用于 SMTP 的问题)
                Issue on how to setup SMTP using PHPMailer in GoDaddy server(关于如何在 GoDaddy 服务器中使用 PHPMailer 设置 SMTP 的问题)
                  <tbody id='ROQhQ'></tbody>

                <small id='ROQhQ'></small><noframes id='ROQhQ'>

                <legend id='ROQhQ'><style id='ROQhQ'><dir id='ROQhQ'><q id='ROQhQ'></q></dir></style></legend>
                    • <bdo id='ROQhQ'></bdo><ul id='ROQhQ'></ul>
                      • <i id='ROQhQ'><tr id='ROQhQ'><dt id='ROQhQ'><q id='ROQhQ'><span id='ROQhQ'><b id='ROQhQ'><form id='ROQhQ'><ins id='ROQhQ'></ins><ul id='ROQhQ'></ul><sub id='ROQhQ'></sub></form><legend id='ROQhQ'></legend><bdo id='ROQhQ'><pre id='ROQhQ'><center id='ROQhQ'></center></pre></bdo></b><th id='ROQhQ'></th></span></q></dt></tr></i><div id='ROQhQ'><tfoot id='ROQhQ'></tfoot><dl id='ROQhQ'><fieldset id='ROQhQ'></fieldset></dl></div>

                        1. <tfoot id='ROQhQ'></tfoot>