php - How can I schedule a function to run, after one of my function is completed, after a specific time period in laravel?
I have a ftp function which moves file from one folder to other(say folder a to folder b) when a button is clicked. It works perfectly. I want a function that will run 30 minutes after the above function is called(i.e. after the file is moved from a to b). How can I schedule such a task in laravel?
I want to do this, because after that file is moved few functions are executed and then if the person forgets to remove the file then that can be dangerous. So I need to check, 30 mins after the file is moved from a to b, whether the file has been moved back or no.
Answer
Solution:
This sounds like a perfect opportunity to make use of Laravels queues, which also allow for delayed dispatching as you can find in the documentation when looking for queuing and delayed dispatching.
Basically, you will need a job that you can push onto the queue like the following
You will then be able to dispatch the job like so:
Of course this solution expects you to have set up Laravel queues properly. There is different ways you can do this, but I guess the documentation is your best friend regarding this (see here).
Answer
Solution:
You need CRON JOB - Laravel Scheduler
Class example:
Then you need to switch on cron jobs on server:
Here you have details: https://laravel.com/docs/5.6/scheduling
And nice video which explains somethings: https://www.youtube.com/watch?v=mp-XZm7INl8