Khaled_Saiful_Islam
Khaled_Saiful_Islam

Reputation: 150

Laravel Schedule command does not work

I used laravel 5 in my project. I wanted to create a scheduler for inserting user. In kernel.php, I put my codes and set the scheduler.

enter image description here

I created a command class named "InsertUser" and put it in kernel.php $commands variable.

enter image description here

In command line, I ran "php artisan schedule:run". But I found "No scheduled commands are ready to run.". If I used call function instead of command function (in lernel.php), it was working fine. Please help me.

Upvotes: 2

Views: 3253

Answers (2)

viswanath608
viswanath608

Reputation: 155

Windows does support Laravel Scheduler but, you've to run the command on your own for multiple times. Since we can't use Windows Task Scheduler to run for every 1 min as we can do with linux crontab. If you're using windows for development environment and want to test if command is working on not you can try this

If you run the

php artisan schedule:run

command for multiple times by giving a min gap for each trial it'll work.

enter image description here

If you want to run directly the command you can follow this.

"path\to\php.exe" "artisan" YourCommand > "NUL" 2>&1 &

In your case

  1. Run "where php.exe" in command prompt

  2. Copy The php location

  3. "paste\your\php\location" "artisan" InsertUser > "NUL" 2>&1 &

Upvotes: 1

Bogdan
Bogdan

Reputation: 44526

The Laravel Scheduler needs a cron job that runs the php artisan schedule:run command periodically, which in turn evaluates any scheduled commands and runs them accordingly.

From your screenshot I see you're running Windows, which means you can't use the job code snippet from the Starting The Scheduler section in the documentation because there is no cron on Windows. Windows is not officially supported for the task scheduler because of that and no instructions for it can be found in the documentation.


You could however get around the problem by creating a batch file, say scheduler.bat, that has the following contents:

cd c:\lamp\www\larasoft
php artisan schedule:run 1>> NUL 2>&1

Then you can add a Windows Scheduler Task to run that file every minute.

Upvotes: 4

Related Questions