我的PHP文件不会被cronjob

时间:2018-01-21 11:03:38

标签: php ubuntu server cron

我希望我能在正确的位置发帖,我想我应该去linux区域,但这可能是代码问题。

我有以下php脚本:

<?php


use function commands\createWalletsForMain;
use function commands\creditWallet;
use function commands\debitWallet;
use function commands\getConfig;
use function commands\selectAlts;
use function commands\selectMains;
use function commands\updateConfig;
use function commands\selectUncreditedTransactions;
use function commands\selectWallet;
use function commands\updateTransaction;


include_once '../vendor/autoload.php';
include_once '../processors/commands.php';
include_once '../secret/esiConn.php';
include_once '../secret/dbconn.php';

$newConn = createConnection();
$mains = selectMains($newConn);
$uncreditedTransactions = selectUncreditedTransactions($newConn);

use Monolog\Logger;
use Monolog\Handler\StreamHandler;
$log = new Logger('wallet');
$log->pushHandler(new StreamHandler("../processors/logs/wallet.log"));


if($uncreditedTransactions->rowCount() != 0) {
    foreach ($uncreditedTransactions as $row) {
        if(selectWallet($newConn,$row['character_id']) != null) {

            creditWallet($newConn, $row['character_id'],$row['amount']);
            updateTransaction($newConn,$row['transactionID']);
            $log->warning($row['character_id']." credited with ".$row['amount']);
        }
        else
        {
            $log->warning("User has no wallet");
        }
    }
}
else
{
    $log->warning("All transactions credited");
}

if(getConfig($newConn,'ProcessedMonth') == date("m") )
{
    foreach ($mains as $row)
    {
        $totalALTS = selectAlts($newConn,$row['main_id'])->rowCount();
        if(selectWallet($newConn,$row['main_id']) != null) {
            debitWallet($newConn, $row['main_id'], ($totalALTS + 1) * 50000000);
            $log->warning($row['main_id']." has been debited ".(($totalALTS + 1) * 50000000).' isk.');
        }
        else
        {
            $log->warning("User has no wallet");
        }
    }
    updateConfig($newConn,'ProcessedMonth',date('m', strtotime('+1 month')));
}

foreach ($mains as $row) {
    if(selectWallet($newConn,$row['main_id']) == null)
    {
        createWalletsForMain($newConn, $row['main_id']);
        $log->warning('Wallet has been created for '.$row['main_id']);
    }
}
closeConnection();

我在apache2服务器上添加了文件,并在crontab中添加了以下行:

*/3 * * * * /usr/bin/php /var/www/eve/processors/wallet.php

但是它没有执行它,我已经尝试在控制台中手动运行代码运行php /var/www/eve/processors/wallet.php,这确实触发了脚本并且它可以工作。

我有点失落......我已经试着弄清楚了两天......

1 个答案:

答案 0 :(得分:0)

设法解决了问题...。我的代码实际上是问题。我的include_once造成了这种情况,因为这些路径永远都不能这样声明,现在我已经了解了。我的坏事:)