Ryan Kelly
Ryan Kelly

Reputation: 173

cron job not executing the php script

today i learned about cron jobs, i opened SSH and followed along with the 1and1 cron job tutorial, the tutorial file and instructions worked fine however when i did the same steps but with my own PHP script it didnt work, below is the cron job command i used

* * * * * /usr/bin/php /path-to-webspace/heal.php

and below is the heal.php file, this file works as intented without cron as i tested it beforehand

<?php

include('onedirectorydown/database_connection.php');

$resetAllHealth = "UPDATE users SET Health = Health + 1000";
$executeAH = mysqli_query($dbc, $resetAllHealth);

?>

i want it to execute every minute as im just testing it to see if it works but it doesnt, however the sample in the 1and1 tutorial worked and i basically followed along exactly, i just the file contents to whats in the heal.php

could someone tell me why it is not executing?

Upvotes: 1

Views: 3284

Answers (2)

Andreas Christodoulou
Andreas Christodoulou

Reputation: 650

Common issues with CRON jobs are that required include files aren't working properly. For example:

include '/database.php';

Might try to include /var/www/database.php when executed from the browser, but might try to include /home/username/database.php when executed from the CRON job of the appropriate user.

Consider replacing calls with

include $_SERVER['DOCUMENT_ROOT'].'/database.php';

and seeing if that helps.

Upvotes: 1

napolux
napolux

Reputation: 16094

Looking at your last comment, maybe you don't have the right mysqli extension installed into the php.ini file for cli (usually under /etc/php5/php.ini).

Remember: "apache" scripts and "command line" scripts have two different php.ini files.

Upvotes: 0

Related Questions