在某个时间段启动php脚本

在某个时间段启动php脚本,php,mysql,mysqli,Php,Mysql,Mysqli,我正在制作格斗游戏,玩家可以战斗到“结束时间”(我数据库中的行列)。比造成更多伤害的玩家将是赢家。所以每次当一行的结束时间用完时(即使站点上没有人),我都想启动一个PHP脚本来更新该行。我在某个地方读到应该使用MySQL触发器,但我不知道如何使用它。有人能帮我吗 PHP脚本如下所示: $query = "SELECT attacker, defender, attackerdmg, defenddmg FROM battle"; $results= mysqli_query($conn, $qu

我正在制作格斗游戏,玩家可以战斗到“结束时间”(我数据库中的行列)。比造成更多伤害的玩家将是赢家。所以每次当一行的结束时间用完时(即使站点上没有人),我都想启动一个PHP脚本来更新该行。我在某个地方读到应该使用MySQL触发器,但我不知道如何使用它。有人能帮我吗

PHP脚本如下所示:

$query = "SELECT attacker, defender, attackerdmg, defenddmg FROM battle";
$results= mysqli_query($conn, $query);

while($Row = mysqli_fetch_assoc($results))
{
    $attackerdmg= $Row['attackerdmg'];
    $defenderdmg = $Row['defenderdmg'];
    $attacker = $Row['attacker'];
    $defender = $Row['defender'];
}

            if($attackerdmg>$defenderdmg)
            {
                $query = "UPDATE fight SET winner= '$attacker'";
            }else 
            {
                $query = "UPDATE fight SET winner= '$defender'";
            }
                $Results= mysqli_query($conn, $query);

你应该考虑使用Con Work。请看这些和

这是迄今为止我发现的最好的PHP代码解释:

简言之:

虽然安排一个新作业的语法乍一看可能令人望而生畏,但一旦你把它分解了,其实理解起来就相对简单了。cron作业始终有五列,每列表示按时间顺序排列的“运算符”,后跟要执行的完整路径和命令:

\* * * * * home/path/to/command/the_command.sh
每个按时间顺序排列的列都与任务的时间表有特定的相关性。详情如下:

Minutes represents the minutes of a given hour, 0-59 respectively.
Hours represents the hours of a given day, 0-23 respectively.
Days represents the days of a given month, 1-31 respectively.
Months represents the months of a given year, 1-12 respectively.
Day of the Week represents the day of the week, Sunday through Saturday, numerically, as 0-6 respectively.
30 8 * * 6 home/path/to/command/the_command.sh

因此,例如,如果一个人想在每个月的第一天上午12点安排一项任务,它将如下所示:

0 0 1 * * home/path/to/command/the_command.sh
如果我们想安排一个任务在每周六上午8:30运行,我们可以这样写:

Minutes represents the minutes of a given hour, 0-59 respectively.
Hours represents the hours of a given day, 0-23 respectively.
Days represents the days of a given month, 1-31 respectively.
Months represents the months of a given year, 1-12 respectively.
Day of the Week represents the day of the week, Sunday through Saturday, numerically, as 0-6 respectively.
30 8 * * 6 home/path/to/command/the_command.sh
还有许多操作员可用于进一步自定义计划:

Commas is used to create a comma separated list of values for any of the cron columns.
Dashes is used to specify a range of values.
Asterisksis used to specify 'all' or 'every' value
访问完整文章的链接,它解释:

  • 如果要手动输入/编辑cronjob,它的格式是什么
  • 如何使用PHP和SSH2库作为用户进行身份验证,您将编辑哪个crontab
  • 完整的PHP类,包含身份验证、编辑和删除crontab项所需的所有方法

  • 是的,看起来我需要一份老朋友的工作。但要理解这一点需要一些时间:我认为这将是你能得到的最简单、最可靠的解决方案。鉴于你的活动类型,这是值得学习的。想想看,我已经把其中一个链接中最流行的答案复制到了我的答案中。