Reputation: 1278
I'm using larave 5.1 with php5, i try to create my cron job to remove unpaid invoice in time i want, but i testing it to print an userlog to help me know that the job is working.
This is my app/Console/Kernel.php
protected $commands = [
\App\Console\Commands\Inspire::class,
\App\Console\Commands\RemoveUnpaidInvoice::class,
];
protected function schedule(Schedule $schedule)
{
$schedule->command('removeUnpaidInvoice')->everyMinute();
// $schedule->command('inspire')->hourly();
}
And this is my RemoveUnpaidInvoice class :
public function handle()
{
UserLog::create([
'user_id' => '3',
'title' => 'Cron Testing',
'log' => 'Time : ' . date('H:i:s')
]);
}
After my files done, i run this command at my terminal to run my cron:
php artisan schedule:run
After i run schedule artisan command, then my terminal show this message :
Running scheduled command: '/usr/bin/php5' 'artisan' removeUnpaidInvoice > '/dev/null' 2>&1 &
I think it's work, then i check my database to look the userlog is created or not, and it's created, the user log is added new via cron.
But the problem is, i wait for one minute, and no userlog added, wait for 2 minute, 3 minute and more, there's no another userlog added to my database?
How to fix it? am i made a mistake??
Upvotes: 0
Views: 14837
Reputation: 1379
Here is the only Cron entry you need to add to your server:
* * * * * php /path/to/artisan schedule:run >> /dev/null 2>&1
This Cron will call the Laravel command scheduler every minute. Then, >Laravel evaluates your scheduled tasks and runs the tasks that are due.
You need start the cron, no run php artisan schedule:run
in the console.
Upvotes: 5