Reputation: 647
First time I am setting up a cron job. I have one simple PHP file. When this file is called it will insert one record in the database.
<?php
mysql_connect("localhost","root","");
mysql_select_db("cron_db") or die(mysql_error());
$tm = time();
$sql = "insert into test(time) values(".$tm.")";
if(mysql_query($sql))
{
echo "done";
}
?>
I have uploaded this file to my server in "public_html/dev/insert.php"
For this i have written the below command
1 * * * * /usr/bin/php /home/domain/public_html/dev/insert.php
It isn't working. Can you help me to fix this?
Upvotes: 0
Views: 284
Reputation: 302
What about piping the output of the cron to a "logfile" ?
Be sure of running the cron with the good user, having right permissions on the file
/home/domain/public_html/dev/insert.php > /home/domain/public_html/dev/insert.log
also check your php's cli php.ini settings & php error_logs
Upvotes: 0
Reputation: 13107
The line
1 * * * * /usr/bin/php /home/domain/public_html/dev/insert.php
will execute the cron job each first minute of an hour. What you want is:
*/1 * * * * www-data /usr/bin/php /home/domain/public_html/dev/insert.php
Note, that I've also inserted a column with the user which should execute the file (in this case, the webserver user. Could also be root or your username.)
Upvotes: 1