I have a cron set to run a php file but for some reason it doesn’t work when the time comes. I can manually call same file in terminal and it works fine. No error message as well.
Note: There are many more jobs set for different folder&files and they all work fine. Permissions are same as well.
Thanks
CRON
30 2 * * 1,2,3,4,5 php /var/www/html/cronjob/update-db.php
PERMISSIONS
drwxr-xr-x 2 root root 4096 Nov 20 10:17 cronjob
-rwxr-xr-x 1 root root 5808 Nov 21 17:21 update-db.php
- conn.php is being used by many other cronjobs and works fine.
- this code works fine when I call run it in terminal.
- every other cronjob works fine apart from this.
CODE
require_once "/var/www/html/dbfolder/conn.php";
function write_log($message)
{
$filename = 'update-sis-assessment-column-log.txt';
if (file_exists($filename))
{
$handle = fopen($filename, 'a');
}
else
{
$handle = fopen($filename, 'w');
//chmod($filename, 0644);
}
fwrite($handle, $message . "\r\n\r\n");
fclose($handle);
exit;
}
if (connectDB() === true)
{
$query = "SELECT.......";
$rcset = mysql_query($query);
$terms = null;
if (@mysql_num_rows($rcset) > 0)
{
while ($records = mysql_fetch_array($rcset))
{
if (ctype_digit($records['Term']))
{
$terms .= "'" . substr($records['Term'], 0, 4) . "-01', ";
}
}
$terms = substr($terms, 0, -2);
}
write_log('DONE : ' . $terms);
}
make sure that the php executable is in your path OR put the full path to php in the cron job like
if you are not sure where php is located you can run
to get the path