0

I'm using Indatus/dispatcher for Laravel 4.2. It is basically a Cron job based Task Scheduler.

I am trying to run a Cron job every minute, and I am getting this error on the live server (but it works fine on my local machine). Here is what I have done:

<?php

use Indatus\Dispatcher\Scheduling\ScheduledCommand;
use Indatus\Dispatcher\Scheduling\Schedulable;
use Indatus\Dispatcher\Drivers\Cron\Scheduler;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Input\InputArgument;

class TestCommand extends ScheduledCommand {

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

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'Check if the meberships are verified.';

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

    /** 
     * When a command should run
     *
     * @param Scheduler $scheduler
     * @return \Indatus\Dispatcher\Scheduling\Schedulable
     */
    public function schedule(Schedulable $scheduler)
    {
        return $scheduler->everyMinutes(1);
    }

    /**
     * Execute the console command.
     *
     * @return mixed
     */
    public function fire()
    {
        Log::info('I was here @ ' . date('H:i:s'));
    }

    /**
     * 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),
        );
    }

}

So basically, I'm just writing a line in my log file (i.e. Storage/laravel.log) every time the scheduler is run. When I do php artisan scheduled:run on my local machine, it writes a new line in my log file.

Now, I've uploaded the code on my server and have created a Cron job as:

[http://awesomescreenshot.com/09a64zii1f](http://awesomescreenshot.com/09a64zii1f)

The Cron job is running every minute as expected and the log file is also being updated every minute, but instead of the message I am writing in log file, its writing following error every minute:

[2016-09-24 09:20:01] production.ERROR: exception 'InvalidArgumentException' with message 'Command "command:check" is not defined.

Did you mean this?

command:make' in /home/mhjamil/public_html/l4-cron/test/vendor/symfony/console/Symfony/Component/Console/Application.php:564

Stack trace:
 #0 /home/mhjamil/public_html/l4-cron/test/vendor/symfony/console/Symfony/Component/Console/Application.php(190): Symfony\Component\Console\Application->find('command:check')
 #1 /home/mhjamil/public_html/l4-cron/test/vendor/symfony/console/Symfony/Component/Console/Application.php(124): Symfony\Component\Console\Application->doRun(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
 #2 /home/mhjamil/public_html/l4-cron/test/artisan(58): Symfony\Component\Console\Application->run()
 #3 {main} [] []`

And by the way, I've registered the command in app/start/artisan.php as

Artisan::add(new TestCommand);

Also the command php artisan command:check runs successfully on my local machine, but when I upload it to my server it says Command "command:check" is not defined.


And one more thing, on my server I have added a route and did Artican::call("command:check");. Now whenever I reload this page, it logs an entry successfully in the log file. But its giving error when done through cron job. So I am guessing the problem is somewhat related to cron job or server settings.


I have tried changing cron command to:

/usr/bin/php /home/mhjamil/public_html/l4-cron/test/artisan command:check 1>> /dev/null 2>&1

previously I was using schaduled:run but still same issue :(

Sᴀᴍ Onᴇᴌᴀ
  • 8,218
  • 8
  • 36
  • 58
Jazzbot
  • 385
  • 1
  • 4
  • 18
  • Try composer dump on server – Vikash Sep 24 '16 at 10:26
  • @Vikash I've tried doing `system('composer dump-autoload');` and `exec("composer dump-autoload");` but still no luck. Is there any other way of doing `composer dump-autoload` through code, I'm using cpanel based hosting so have no access to console. – Jazzbot Sep 24 '16 at 10:36
  • @Jazzbot I would quickly forget about running stuff on a machine you have no shell access to. Also, is this a new project? I'm puzzled that you're using Laravel 4.2. – mniess Apr 27 '17 at 17:59
  • it was an old project and client asked for a few changes. – Jazzbot Oct 30 '17 at 11:07

0 Answers0