Khaled_Saiful_Islam
Khaled_Saiful_Islam

Reputation: 150

In Laravel, command function of Schedule class is not working

I am using Laravel 5 for my Project. I want to create a scheduler that will insert a user data in my database at every five minutes. I am using windows and I have created a windows scheduler task with a BAT file that will run in every minutes.

In laravel part, I added my codes in kernel.php, please take a look:

enter image description here

I also created a class in Commands folder named "InsertUser". Please take a look:

enter image description here

But it is not working, it always show "No scheduled commands are ready to run." message.

For your help, I want to add other information as well. In kernel.php, when I used call method instead of command it is working. Please take a look:

enter image description here

In CLI message:

enter image description here

Call function is working fine but Command function is not working. Please help me with your solid knowledge. Thanks.

Upvotes: 0

Views: 1558

Answers (2)

Shanka SMS
Shanka SMS

Reputation: 654

Go to your project path and run bellow code and check the output.

php artisan insert:user

Upvotes: 0

Borja Marco
Borja Marco

Reputation: 54

You are missing this command, wich you have to add it to crontab, however this only run in linux or similars.

* * * * * php /path/to/artisan schedule:run >> /dev/null 2>&1

In Windows is also possible with Windows Task Scheduler but the downside is the lowest it can be set to is Every 5 Minutes which is still ok for a testing environment.

I created a batch file scheduler.bat with the following contents

cd \path\to\project\ C: \path\to\php\php-5.6.3\php.exe artisan schedule:run 1>> NUL 2>&1

Change directorys to match your setup.

If you have php successfully added to your PATH variable then the second line can read php artisan, there is no need for an exact location. But you will need to make sure you browse to your project root first.

Then launch the task scheduler Windows Key + R then paste in Taskschd.msc and hit enter.

Then click Create Basic Task on the right in the Actions pane.

Name your task something so you will know what it is for if you need to modify it or are running multiple projects then click Next.

Leave this page set to Daily for now and click Next.

Leave this page as defaults as well and click Next.

Make sure Start a Program is selected and click Next.

Browse to the batch file we just created and then click Next then click Finish.

Now, select Task Scheduler Library on the left, and find your task in the middle pane and right-click and click Properties

Go to the Triggers tab, click Daily in the list and click Edit.

The drop-down at the top next to Begin the task change to At Log on for Any user

Check the box that says Repeat Task Every and choose 5 Minutes from the drop-down. The drop-down after for a duration: on the same line choose Indefinitely.

Click OK. Done.

Then right-click on your task in the middle pane and click Run to initiate it.

Upvotes: 1

Related Questions