Reputation: 35
I am trying to run a cron job every minute that will insert a new row into a specific table every minute.
I added the path to the feedUpdate.php file and 1 0 * * *
to execute it every minute. The feedUpdate.php looks like this:
<?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);
?>
This script works fine when I just write the path directly in the browser, but it doesn't run automatically every minute.
Any ideas why?
I am using 000webhost at the moment as it's free, but I know for a fact that it does run cron jobs as I have one that runs daily clearing temporary files.
Upvotes: 0
Views: 3865
Reputation: 16
* * * * * 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)
To run every minute try this:
* * * * * php /path/to/file/runScript.php
Stackoverflow: How can I write a PHP cron script?
Mirror: http://iswwwup.com/t/7cb7527ceffc/how-can-i-write-a-php-cron-script.html
Upvotes: 0
Reputation: 782315
To run every minute, the cron job schedule should be * * * * *
.
1 0 * * *
means to execute every day at 00:01
.
Upvotes: 2