Yii2 how to send mail in the background

I did all kinds of searches on this topic, and there seem to be many ways to send email after a custom event. For example, register an account. I do not like to send it as part of the send page, because it tends to take a few seconds. I used to configure cron to run every 10 minutes or so, and then run a script to check if I need to send mail. This works, but it seems like such a waste of resources needs to be checked every 10 minutes.

My question is ... is there a way to initiate sending mail right after the page is sent, but not during the processing of this page? In other words, transfer control of the page to another script after its completion. I do not think this is possible with PHP, but thought I would ask.

I use MySQL and I believe that it is possible to create database triggers after creating a record, but not very familiar with it.

+4
source share
1 answer

With Yii 1, I am using yii-resque. example for yii1: http://www.yiiframework.com/extension/yii-resque/

Maybe this is good for yii 2.0. Stream: Browser => submit => save data => call Resque Job (this job runs in the background) => Done. The user does not need to wait.

For Yii2, you can use yii2-resque: https://github.com/sprytechies/yii2-resque

-1
source

Source: https://habr.com/ru/post/1599827/


All Articles