我试图每分钟运行一个 cron 作业,每分钟将一个新行插入到特定表中。
我添加了 feedUpdate.php 文件的路径和 1 0 * * *
每分钟执行一次。 feedUpdate.php 如下所示:
<?php
require_once("../php_includes/db_conx.php");
$sql = "SELECT * FROM posts ORDER BY RAND() LIMIT 1"; //Select a random row from 'posts'
$query = mysqli_query($db_conx, $sql);
$row = mysqli_fetch_array($query, MYSQLI_ASSOC);
$id = $row['id']; //get the id of that specific random post selected
$sqlins = "INSERT INTO postfeed (postid, time) VALUES ('$id',now())"; //Insert the new post id into the feed table.
$queryins = mysqli_query($db_conx, $sqlins);
?>
当我直接在浏览器中写入路径时,该脚本工作正常,但它不会每分钟自动运行。
有什么想法吗?
我目前使用的是 000webhost,因为它是免费的,但我知道它确实运行 cron 作业,因为我有一个每天运行清除临时文件的作业。
最佳答案
要每分钟运行一次,cron 作业计划应为 * * * * *
。
1 0 * * *
表示每天00:01
执行。
关于php - 使用 cron 作业每分钟将新行插入表中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31634997/