简体   繁体   中英

CronJobs Permission Denied

Okay, so I made a cronjob to run every two minutes and set it up to send me an email. Well, this is the cronjob. /home/sites/psychowars.com/public_html/cronjobs/energy_minute.php This is the email I receive.. nice:

/home/sites/psychowars.com/public_html/cronjobs/energy_minute.php: Permission denied

Well, this is the PHP file that's suppose to run.

<?php
require '../stats/users_stats.php';
    {
    if ($energy < $max_energy) {
    $sql = "UPDATE users SET energy=(energy + 1) WHERE id='".$id."'";
    $res = mysql_query($sql);
    }
    }
?>  

Every 2 minutes the user should recieve 1 energy if it's less than their max energy. Any solutions on what's wrong?

try to set $_SERVER["DOCUMENT_ROOT"] manually at the start of the script and don't use relative paths for cronjob scripts:

$_SERVER["DOCUMENT_ROOT"] = "/home/sites/psychowars.com/public_html";
require $_SERVER["DOCUMENT_ROOT"].'/stats/users_stats.php';
if ($energy < $max_energy) {
  $sql = "UPDATE users SET energy=(energy + 1) WHERE id='".$id."'";
  $res = mysql_query($sql);
}

You have answer here

$_SERVER variable is not set from cron job.

If is still not working you can outsource your cronjob with www.guardiano.pm and call an http post or get request to yoursite.com/users_stats.php so you don't need to care about cronjobs. If the only thing that you need is that IMHO you can avoid that

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM