Laravel-4 cron works

I need to learn how to work with cron jobs in Laravel. As I can see, the documentation does not indicate this part. I found a tutorial, but it's about Laravel-3. Can you give me some tips on how to schedule cron work once a day? Do you have a tutorial on this issue?

My code so far looks like this:

JobDaemon.php:

<?php

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

class JobDaemon extends Command {

    /**
     * The console command name.
     *
     * @var string
     */
    protected $name = 'job-daemon';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'Get all recent jobs once a day.';

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

    /**
     * Execute the console command.
     *
     * @return void
     */
    public function fire()
    {
        $this->info('fired');
    }

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

}

I used the following command to configure it

php artisan command:make JobDaemon

And my artisan file is as follows:

<?php

Artisan::add(new JobDaemon);

I get the following from my console ...

johnnemo@johnnemo:/opt/lampp/htdocs/e-support-uop$ tail -f /var/log/syslog | grep -i cron
Jan  1 18:31:09 johnnemo crontab[4484]: (johnnemo) REPLACE (johnnemo)
Jan  1 18:31:09 johnnemo crontab[4484]: (johnnemo) END EDIT (johnnemo)
Jan  1 18:35:01 johnnemo CRON[5054]: (johnnemo) CMD (php /opt/lampp/htdocs/e-support-uop/artisan job-daemon)
Jan  1 18:35:02 johnnemo CRON[5053]: (CRON) info (No MTA installed, discarding output)
Jan  1 18:39:01 johnnemo CRON[5064]: (root) CMD (  [ -x /usr/lib/php5/maxlifetime ] && [ -x /usr/lib/php5/sessionclean ] && [ -d /var/lib/php5 ] && /usr/lib/php5/sessionclean /var/lib/php5 $(/usr/lib/php5/maxlifetime))
Jan  1 18:40:01 johnnemo CRON[5076]: (johnnemo) CMD (php /opt/lampp/htdocs/e-support-uop/artisan job-daemon)
Jan  1 18:40:01 johnnemo CRON[5075]: (CRON) info (No MTA installed, discarding output)
+4
source share
2 answers

First you need to make sure your new team is complete, so if you run

php artisan list

"job-daemon"

:

php artisan job-daemon

? Cool, :

export EDITOR=nano

crontab :

[sudo] crontab -e

php:

type php

-

php is hashed (/opt/lampp/bin/php)

, php

/opt/lampp/bin/php

cron, sudo crontab root, :

25 10 * * * /opt/lampp/bin/php /whatever/directory/your/site/is/artisan job-daemon

10:25.

5 ,

*/5 * * * * /opt/lampp/bin/php /whatever/directory/your/site/is/artisan job-daemon

tail syslog , :

tail -f /var/log/syslog | grep -i cron

-

Jan  1 10:25:01 server CRON[19451]: (root) CMD (php /var/www/<siteName>/artisan job-daemon)

, , , , - :

public function fire()
{
    File::append('/tmp/laravel.txt', "fired\n");
    Log::info('fired');
}

tail -f /tmp/laravel.txt

.

+22

OP, , 100%. CPON Jobs cPanel 404 , . :

  • , :

    php artisan

  • ,

  • :

    php

  • "php hashed (/usr/local/bin/php)"

  • CRON . , , , . laravel . , , , "command:"

, laravel CPON Jobs cPanel, :

/usr/local/bin/php /home/sitename/public_html/laravel/artisan command:TotalMadnessUpdateResultsCommand

artisan.php:

Artisan::add(new TotalMadnessUpdateResultsCommand);
+1

All Articles