Implementing and executing cron jobs

The main usage of console applications consists in the execution of periodic tasks using cron job (on Linux or Unix machines).

We can use console applications to send massive e-mails to perform system maintenance or to check a specific status of the application.

In the next example, we will see how to send an e-mail with a summary of the reservations made in the current date.

Example – sending an e-mail with new reservations of the day

This example illustrates how to send an e-mail with a summary of new daily reservations.

First of all, let's configure the mailer component in console/config/main.php, if it is not already configured.

It is enough to pass a few parameters to the component:

 'components' => [ .. .. 'mailer' ...

Get Yii2 By Example now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.