Hello guys, how are you all? I hope you are all fine. So guys, today we are going to see how we can set a cron job.
That too, we are going to see in the live server and here we are going to use Laravel application. For example, you have a Laravel project and you have to apply cron job in that project. So today we will see how to use it and that too in the live server where we are using Hostinger. So first we will see what is cron job?
So guys, what is cron job? Means For example, you have to do any task, which should be run automatically, daily run should be done. For example, you have to send daily emails at this time, you have to send emails at 8 o'clock, otherwise you have to send emails every minute. So we can't send it every time, click it, it will go, click it, it will go, right? We can send it, but time will go, but when we set the cron job, then every time it will go automatically.
What do we call it? We don't need to take pressure. We don't need to do anything like click send or button.
They get along with us automatically. So, we can set it like that. We also get messages once a day.
They also set a cron job there. So, we can set every minute there. We can set the hours daily.
If you want to set it daily, you can do it. If you want to do it monthly, you can do it monthly. If you want to do it yearly, you can do it yearly. And it works automatically. Once we have to write the function which is work, that is, the exact function as it should be, then it is automatically worked.
So that is called a cron job where we can also do scheduling. So how does it work in Laravel? There is scheduling, guys. It is inbuilt where we can schedule our task every minute and we can perform that task every minute. So guys, we will see that today.
So let's start now. So here you will see that this is our hosting house. You must be knowing that if you use live server then how is Hostinger? So this is our Hostinger.
So now what we will do is we will go to our project and I will show you guys how I have scheduled and how it runs. And how we can set the cron job here in Hostinger. So I am going here.
So guys today the internet is a little slow so it is taking some time. So here I made a file by testing, so here I will show you where it is, so go to the app, then here console Means we use a command, what do we do with that command, we have made a test command in this command, so what will be mine in this, whatever I am going to set, whatever my function is, I am going to set everything in this test command So here I have made a dollar signature and got one of my commands, by updating the membership colon and here you can see update elite membership status for users you can give any description you can give any name but we have to use this and I will tell you one more thing so you can call this command then guys you can see here I have used a handle function here my logic I have written my logic here so here I have written that every user is fetching from my database and in that database there are two columns what I am doing is nulling them and how to null it? every minute should be null I will show you that in my database I am nulling these two columns I will show you that so in main logic our logic which we are performing will come in test command so I made test command here is my logic here I told you I have taken command fine so where did I schedule it so to schedule it when we make commands or test commands then our here guys a file is made by doing kernel in this command ok so we have to open it so in this kernel we can do it what we can schedule it ok so where in the kernel you will see here the main is also very important guys here I have taken a path command test command class so which path is it then you know what path i have taken so command means the command in console in commands there is test command so i have to give the same path here class ok so here i have given class and here i have taken path where my test command is as you can see carefully because it is very important here Cron jobs which we set in live server is very important guys so please see carefully so here I have set the class then see here guys here schedule is function Travel is generated automatically in kernel.php So here we can schedule So here you can see my schedule And I have scheduled here Membership colon update every minute Means what should happen Command should run every minute And where did this membership update come from I had already told you In test command Here I have taken a command Signature membership colon update So I have taken it here I have to update this every time Guys, it's not like we have to give membership You can give any name here But whatever name you give here We have to give the same name in the kernel Where we are running every minute This command So you have to give it there too So here our schedule is also done Means what happened to us We have written the function Whatever we have to run every minute I have written the function in the test command And where did I set it I have written the function in the test command schedule here ok so our schedule is done everything is done now we have to run it to run it we have to set in hosting cron job then only it will run to set that we have to go to dashboard I delete it for you guys so I have to go to dashboard ok so here where did it go? so here you will get the advanced option why am I not getting the advanced option? when we go to the dashboard of our website we get the advanced option below so we have to go to the advanced option and here we have to you will also get a cron job and here you will see that there is a cron job so we have to click it here we have to set a cron job ok so here it is visible that create a new cron job ok so guys here see I have already made a cron job which runs every minute here you will see star means every minute and one more thing I will tell you guys that when you go to Laravel here Laravel understand your task scheduler and type in Laravel Here you will find all the scheduling tasks.
Here you will find all the tasks. If you come down, you will find all the tasks. Here you can see which tasks we can schedule. Here you can see every second. Here you can see every second.
Here you can see every second. Here you can see every second. Here you can see every second.
Here you can see every second. We can set it as per our wish. Monthly, quarterly, yearly, yearly on, time zone, this time should be there. We can set that too. Laravel is inbuilt, which we have to use only.
You must be understanding that I have used it here. I have used every minute here. Now, suppose you have to set a cron job here. For that, we have to take our path. Where is our file?
So where is my file? Home This is my username Then here is my public and this is my html This is my test So suppose I went here Both are the same So let's go here Let's go to the dashboard I will go to file manager So where will I tell my path? Ok So user and home are taken by themselves So where is my public? In the test So here it is You see here Home and username it will take guys by default okay So in public what I have is test That's it guys, I have scheduled in test only After that what we have to do is do RTSing And schedule colon run Schedule colon run means Here all the tasks we have scheduled will be run When we will use schedule When we will use schedule Means I have set one now so I I will take one more here and I can set it every hour. I will take an hourly here.
I will pick this hourly and set it here. Now here we have two schedules. So here we have to change the membership two ways, it looks the same.
So what will be here will be different. so these two commands when we take in cron job schedule,run all the ones we write here will be run all the ones we write will be run here when we take this schedule,run all the ones will be run you have to run only one so we have to copy it and come here and here we have to give code I will take it and here when you are using Lara you have to select PHP, do not custom select ok, select PHP, keep in mind, so what we have to do here is that I have given a path here command, so I have to pick up this command and here guys, I have to put it here, then what will happen, this particular task will be run guys, that much only, but when I use this schedule, schedule run then all the tasks will be run so this is easy to use let all the tasks be run then we have to select the minutes and hours if you want to run every minute then you have to select every minute if you want to save then you have to select every hour if you want to save then you have to select every hour every month here is also a star every weekend so we have to set and save it after saving it will look like this you can delete and delete it and we have to see the output of this schedule and run so here I will see the output also when this run has happened and time will also be visible here so this is fine, what you can do is you can set a cron job in hosting I hope you understand Now I will show you how to run my cron job every 1 minute. So for now I refresh here.
And here I am doing zero. So I quickly enter it. 55.1.1 I will wait for 1 minute and then check it.
I will not pause the video because you will understand. refresh as you can see it is running 0 because it is running every minute it is running 0 so guys you can do you can set the round job suppose if i put it again it will run 0 again after every minute ok so guys you can set cron job in your laravel application ok so i hope guys you understand ok one more guys for example how to make video in localhost and how to make in server i will show you guys in one more video where i will show you guys ok so guys please stay tuned to my channel so like this you will get many videos informative videos ok So like my channel, share and subscribe my channel. Thank you so much guys.
Keep supporting guys.