【问题标题】:cron job for laravel 4 won't worklaravel 4 的 cron 工作不起作用
【发布时间】:2016-09-01 09:43:39
【问题描述】:

我正在关注这个 Cron Job with Laravel 4 作为 laravel 4 中 cron 的教程,但它似乎不起作用。这是我的/app/commands/ReleaseOptionBooking.php

<?php

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

class ReleaseOptionBooking extends Command {

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

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'Check booking expirations';

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

    /**
     * Execute the console command.
     *
     * @return mixed
     */
    public function fire()
    {
        $to = "bikegearup@gmail.com";
        $subject = "My subject";
        $txt = "Hello world!";
        $headers = "From: admin@theskitrip.ca" . "\r\n";

        mail($to,$subject,$txt,$headers);
    }

    /**
     * Get the console command arguments.
     *
     * @return array
     */
    protected function getArguments()
    {
        return array(
            array('example', InputArgument::REQUIRED, 'An example argument.'),
        );
    }

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

}

这是/app/start/artisan.php

Artisan::add(new ReleaseOptionBooking);

在我服务器的crontab -e

*/10 * * * * php /var/www/myproject/protected/artisan release:option

有人知道我的案子吗?

我收到了这个错误:

  [RuntimeException]
  Not enough arguments.



release:option [--example[="..."]] example

【问题讨论】:

    标签: php laravel-4 cron


    【解决方案1】:

    你有 ssh 访问你的服务器吗? 你可以尝试手动执行命令吗:

    php /var/www/myproject/protected/artisan release:option
    

    您是否看到任何错误消息?有输出吗?

    【讨论】:

    • 所以 cron 作业运行正常。用你的代码解决问题。从受保护的函数 getArguments() 中删除所需的参数检查
    【解决方案2】:

    从您的命令代码中删除这些示例:

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

    【讨论】:

      猜你喜欢
      • 2018-10-24
      • 2013-01-29
      • 1970-01-01
      • 2013-01-09
      • 2013-10-09
      • 1970-01-01
      • 1970-01-01
      • 2014-11-10
      • 2016-09-19
      相关资源
      最近更新 更多