*cover image is from crontab.guru a sample of how to write cron schedule expressions.

Register for our FREE Online Meetup here: https://www.meetup.com/Women-Who-Code-Manila/events/281998299/


The way I see it, there are two ways to invoke your PHP(or any language) piece of code:

  1. HTTP - a web service / endpoint / API
  2. Command Line - (CLI) / via terminal

It is possible that the code you use inside any of those two ways might need a schedule depending on your business or feature needs.

Maybe you would need to trigger a database backup every lunch time everyday or every night. You can either trigger this via an HTTP endpoint, you call that on a browser or you sign in via SSH to your terminal and trigger the executable file / binary file / PHP file to run the backup code. This becomes repetitive and takes a lot of effort to a person to execute it manually. Thus, comes a tool called "Cron".

Laravel Task Scheduling comes in handy for setting up cron jobs in a human readable way, minimizing the overhead learning curve of Cron or Crontab. You only setup your scheduled tasks inside your code once and you are good to go.

<aside> 💡 You will only need to add one scheduled task to crontab that would trigger all the scheduled tasks inside your code. You may head on to Running the Scheduler


What is a Cron Job?

The cron command-line utility, also known as cron job[1][2] is a job scheduler on Unix-like operating systems. Users who set up and maintain software environments use cron to schedule jobs[3] (commands or shell scripts) to run periodically at fixed times, dates, or intervals. - Wikipedia

I remember the first time I used Cron. I accidentally ran a job every minute and I forgot that it is actually going to send an email every minute to a list of emails. 😅 It's because I was unfamiliar to how the Crontab works.

Okay, so what is Crontab?

The crontab is a list of commands that you want to run on a regular schedule, and also the name of the command used to manage that list. Crontab stands for “cron table, ” because it uses the job scheduler cron to execute tasks; cron itself is named after “chronos, ” the Greek word for time.cron is the system process which will automatically perform tasks for you according to a set schedule. The schedule is called the crontab, which is also the name of the program used to edit that schedule. - GeeksForGeeks