Aynchronous services in Yii


I have a couple of questions I’m hoping to get feedback on. I find it to take too long time to send mails within the same “thread” for ex. when a user registers and I need to send a registration mail. I am currently trying out different approaches to solve this issue.

Right now I have created a controller class which takes some information and will send a mail based upon this. I then use a models afterSave function to send a curl request to this controller with a timeout of 1 sec.

Question 1: When triggering this, i.e. saving the model, and while debugging, I expected to get a "new" request to debug the controller action separately. This does not happen, the browser is processing, and is showing an error after the function which called curl is returning (in the first controller). So I was surprised. Do anyone have an explanation for that? I am surely making a separate GET request on the second controller.

Question 2: I have other services which are just controller actions as well, and I’m planning to use a cron job to execute them as a “timed service”. Does anyone have a best practice for this? (I am using encrypted “passwords” to be able to execute the controller actions)