AliRezaBeitari's avatar

cPanel Cron Job

How can I set a cron job on cPanel for laravel?!

Thanks.

0 likes
6 replies
AliRezaBeitari's avatar

I only want a cron job that runs every day! Every minute is heavy!!

Cronix's avatar

You misunderstand.

Yes, the single actual cron job gets executed every minute.

But, you define the actual schedule using laravels scheduler. If you read the entire docs I linked to, you'll see that you can schedule something to run daily(). So when the cron job runs (every minute), it checks laravel to see if there's actually something to do. If not, it doesn't do anything. Then it checks again another minute later to see if there's something to do, etc...

What this let's you do is instead of having to have 30 cronjobs set in crontab, you can just have 1, and all of the scheduling is done in code instead of having to have a separate cron job for each one. Read the docs...

AliRezaBeitari's avatar

Yes I have understood but I don't want to run a cron job every minute and then laravel check if one day is passed! Because I only need a single cron job and I want to set that to run every day. Running it every minute is waste!

Cronix's avatar

Well, the docs show this for running the artisan schedule:run command every minute to execute the schedule...

* * * * * cd /path-to-your-project && php artisan schedule:run >> /dev/null 2>&1

So instead of schedule:run, use your own artisan command there that you created and set the frequency to run when you need instead of every minute?

jlrdw's avatar

I'm on the way to the grocery store.

Please or to participate in this conversation.