As a hosting owner, have you ever imagined that there are a lot of technical things that don't need to be done manually? Yes, both in cPanel and Plesk, there is a Cron Job feature that you can use to run orders on a scheduled basis.

For example, you want to backup website files every week or send emails to subscribers every Monday. To run this command automatically, we can take advantage of the features provided by hosting, namely Cron Job.

In this article, we will explain what a Cron Job is and its functions and how to create it.

What are Cron Jobs?

Cron is one of the facilities provided by UNIX-based operating systems (Linux is one of them) to run jobs on a scheduled and automatic basis. Scheduled means that the work will take place according to the time we specify.

Cron job is a term that uses cron itself and is repetitive. In the Cron Job there are several things that are needed, including:

Cron job adalah istilah penggunaan cron itu sendiri dan sifatnya berulang. Pada Cron Job ada beberapa hal yang diperlukan, diantaranya :

  1. Time or schedule

In the cron job there are 5 time fields in its execution. Details of the time field as shown below:

The Cron Job in the hosting panel is quite easy. We don't have to remember the scheduling time setting of the Cronjob itself because it is already displayed in the time display.

  1. Command

In this section we can write Linux commands or PHP scripts to be executed by the Cron Job. We can also fill in the name of the file to be run by the Cron Job.

Functions or benefits of Cron Job

Here, the admin will inform some of the functions or benefits of the Cron Job:

  • Make backups
  • Delete files
  • Running download and upload
  • Doing the process of sending email
  • Can be used for server monitoring
  • Can be used for Laravel symlink creation without SSH

Examples of Using Cron Jobs

Cron Jobs can be used in several frameworks such as CodeIginiter and Laravel. The following admin provides examples of the application of Cron Jobs that can be used:

Cron Job CodeIgniter

  • You have many website subscribers. You want every subscriber to get the latest information updates from the website every Saturday. You send that information to each subscriber's email. This technical work can be done automatically. You can create scripts to run on a scheduled basis by the Cron Job. This makes you do not need to be in front of the computer every Saturday to send emails.
  • You have an invitation application and want to send a reminder to the participants h-1 before the event takes place. This reminder notification can be sent to participants' emails with a script to run Cron Jobs.

Cron Job Laravel

  • You don't need to manually login SSH to clear laravel system cache using Artisan. Create a script that runs the clear cache command so that the Cron Job will run it automatically. This allows every new data does not need to pass through the cache first.
  • Anda baru saja upload file website Laravel ke hosting dan ingin membuat Symlink. Setelah Anda cek, ternyata paket hosting yang dimiliki tidak ada fitur SSH. Masalah ini dapat diatasi dengan pembuatan symlink melalui Cron Jobs.

In Laravel there are also methods that can be used to create Cron Jobs. The following methods can be used:

Method Deskripsi
->cron(‘* * * * *’); run a custom cron schedule task
->everyMinute(); running a task every minute
->everyTwoMinutes(); run a task every 2 minutes
->everyThreeMinutes(); run a task every 3 minutes
->everyTenMinutes(); run a task every 10 minutes
->everyThirtyMinutes(); run a task every 13 minutes
->hourly(); running tasks every hour
->everyTwoHours(); run tasks every 2 hours
->daily(); running tasks every day at midnight
->dailyAt(’13:00′); running tasks every day at 13:00
->twiceDaily(1, 13); run tasks every day at 1:00 and 13:00
->weekly(); run tasks every week at 00:00
->weeklyOn(1, ‘8:00’); running tasks every Monday at 8:00
->monthly(); run tasks every month at 00:00
->monthlyOn(4, ’15:00′); run tasks every month on the 4th at 15:00
->twiceMonthly(1, 16, ’13:00′); run tasks every month on the 1st and 16th at 13:00
->lastDayOfMonth(’15:00′); run a task on the last day of every month at 15:00
->quarterly(); run a task on the first day of every quarter at 00:00
->yearly(); run tasks every year at 00:00
->yearlyOn(6, 1, ’17:00′); run the task every year on June 1 at 17:00
->timezone(‘America/New_York’); Set time zone for task

Cron Job Backup

  • You usually do website editing and want website files to be automatically backed up every 3 days, you can run this in Cron Jobs.
  • Your website is used for registration, and you want to automatically back up the registrant database every 00.00.

Conclusion

Cron is one of the facilities provided by UNIX-based operating systems (Linux is one of them) to run jobs on a scheduled and automatic basis. Cron job is a term that uses cron itself and is repetitive.

There are two things that need to be considered in making a Cron Job, namely time (schedule) and command (command). Cron Jobs have many benefits including being able to be used for backups, uploads, downloads, delete files, automatic email sending and much more.

Was this answer helpful? 0 Users Found This Useful (0 Votes)