dongyuyi5680 2011-02-13 20:17
浏览 59
已采纳

当计时器到达零时执行查询

The idea is pretty simple:

Where the timer is made in Javascript, when it reaches zero it performs a query in PHP that alters the database value to add 1.

The problem is that the timer in question must not be reset with page refresh, just like any browser based game, when you build a new facility.

This is for a school game project, in which you click "Build" and depending on that facility's level it would take X time to upgrade it to a new level, showing a timer that tells the user how much time left until the upgrade is done.

I'm really sorry if the solution is somewhere here, but I swear to god I've searched everywhere but I could not get a decent methodology to do this.

  • 写回答

3条回答 默认 最新

  • dri98076 2011-02-13 20:25
    关注

    Do not rely on frontend script to do this, instead schedule a task in the backend. some ways to do it. If the load and users are less, and timer value is not very high. Put Sleep(10) ( for 10 seconds ) in your script.and call it through your javascript, it will execute the query after 10 seconds :) . And will work even if the browser is closed or page is refrehsed

    Php script :

    <?php
    
      $timer = $_REQUEST['timer'];
      $timer = intval($timer);
       sleep($timer); // sleep for some seconds
       ....rest of the stuff..
    
     ?>
    

    However for heavy use, and large intervals like 15 minutes etc, you can immediately store some information and triggering time in a database, and later on process them with a cron ( scheduled task ) in the backend

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 #MATLAB仿真#车辆换道路径规划
  • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建
  • ¥15 数据可视化Python
  • ¥15 要给毕业设计添加扫码登录的功能!!有偿
  • ¥15 kafka 分区副本增加会导致消息丢失或者不可用吗?
  • ¥15 微信公众号自制会员卡没有收款渠道啊
  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘