php - 使用 cron 作业每分钟将新行插入表中

标签 php mysql database cron

我试图每分钟运行一个 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/

相关文章:

php - 我没有获得所需的 URLRewrite

javascript - 使用 exec() 在 PHP 中执行 nodejs 脚本文件

javascript - 在提交表单之前验证多个文件的文件名

php - 使用 mysql 求和并更新组行

java - 性能插入语句?

mysql - 如何一次执行多个查询,如果一个查询失败,另一个查询就无法执行?

asp.net - ASP 等同于 Ajax?

javascript - 使用javascript在文本框中显示数据

java - JOOQ批量删除ID列表的记录

database - IBM-Watson 云产品中输入要求的数据格式是什么?