【问题标题】:Set Up CronJob In CPanel Laravel在 CPanel Laravel 中设置 CronJob
【发布时间】:2015-10-06 16:01:35
【问题描述】:

我在 cpanel 中设置了一个 cronjob,我使用的是 laravel 4.2。我还设置将 cronjob 发送到我的电子邮件,黄色部分下方是我在电子邮件中收到的错误。

[无效参数异常]

“用户”命名空间中没有定义命令。

//laravel 命令.php

<?php

use Illuminate\Console\Command;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Input\InputArgument;

class CronDelFilesCommand extends Command {

/**
 * The console command name.
 *
 * @var string
 */
protected $name = 'user:active';

/**
 * The console command description.
 *
 * @var string
 */
protected $description = 'Command description.';

/**
 * Create a new command instance.
 *
 * @return void
 */
public function __construct()
{
    parent::__construct();
}

/**
 * Execute the console command.
 *
 * @return mixed
 */
public function fire()
{
    echo "aaa";
}

/**
 * Get the console command arguments.
 *
 * @return array
 */
protected function getArguments()
{
    return array(

    );
}

/**
 * Get the console command options.
 *
 * @return array
 */
protected function getOptions()
{
    return array(
        array('example', null, InputOption::VALUE_OPTIONAL, 'An example option.', null),
    );
}

}

//cpanel中的命令

* * * * * /usr/bin/php /home/project/public_html/artisan user:active > /home/project/public_html/log.txt

怎么了?错误是什么意思?

更新

感谢@KristianHareland,我使用 wget。 :)

【问题讨论】:

  • 尝试使用 wget http://www.website.tld/path/to/file 我在 cPanel cron 作业中也遇到了一些问题,并认为这是最好的解决方法。
  • @KristianHareland 不再使用 laravel 命令了吗?
  • @KristianHareland 谢谢!
  • 没问题,好好的:)

标签: php laravel cron cpanel


【解决方案1】:

我想你忘记将这个命令添加到 artisan app/start/artisan.php

你应该说:

Artisan::add(new CronDelFilesCommand());

别忘了composer dump-autoload 更多信息您可以找到here

【讨论】:

  • 我确实在 artisan.php 中添加了新命令。什么是作曲家转储自动加载?
  • 它只是重新生成需要包含在项目中的所有类的列表(autoload_classmap.php)。非常适合在项目中有新课程时使用。
  • 另外我想推荐你很好lib for Laravel Cron jobs
  • 一件重要的事情。尝试删除选项数组。
猜你喜欢
  • 2020-12-14
  • 2015-11-18
  • 2020-05-20
  • 2018-12-21
  • 2020-04-11
  • 2013-10-12
  • 2014-09-04
  • 2017-10-08
  • 2013-02-28
相关资源
最近更新 更多