【问题标题】:My PHP file will not execute by cronjob我的 PHP 文件不会被 cronjob 执行
【发布时间】:2018-06-30 04:04:27
【问题描述】:

我希望我在正确的地方发帖,我想我应该去 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 的代码,这确实触发了脚本并且它可以工作。

我有点迷茫....我已经尝试了 2 天....

【问题讨论】:

  • 我认为 cron 会通过电子邮件向您发送错误消息。可能是环境问题
  • 我什至检查了 cron 日志,这是它给出的唯一条目:CRON[43414]: (crarsene) CMD (/usr/bin/php /var/www/eve/processors/wallet.php)
  • */3 * * * * /usr/bin/php /var/www/eve/processors/wallet.php &gt; /tmp/wallet.txt 2&gt;&amp; 也许。看看发生了什么
  • 我刚试过tmp/wallet.txt。它说它执行了它CRON[44172]: (crarsene) CMD (/usr/bin/php /var/www/eve/processors/wallet.php &gt; /tmp/wallet.txt 2&gt;&amp;),但在 /tmp 中没有创建 wallet.txt 文件
  • 它执行了吗 - 即文件存在?

标签: php ubuntu server cron


【解决方案1】:

设法解决了问题....我的代码实际上是问题所在。我的 include_once 穿着原因,因为这些路径永远不应该这样声明,现在我已经阅读了它。我的坏:)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-08-07
    • 2015-11-30
    • 1970-01-01
    • 2011-07-19
    • 1970-01-01
    • 2015-04-17
    • 1970-01-01
    • 2023-03-20
    相关资源
    最近更新 更多