[英]Insert new row into table every minute with cron job
我正在尝试每分钟运行一次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
执行。
* * * * * command to be executed
- - - - -
| | | | |
| | | | +----- day of week (0 - 6) (Sunday=0)
| | | +------- month (1 - 12)
| | +--------- day of month (1 - 31)
| +----------- hour (0 - 23)
+------------- min (0 - 59)
要每分钟运行一次,请尝试以下操作:
* * * * * php /path/to/file/runScript.php
Stackoverflow: 如何编写PHP cron脚本?
镜像: http : //iswwwup.com/t/7cb7527ceffc/how-can-i-write-a-php-cron-script.html
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.