How To "send Mail Message And Jabber Message"

I am using swiftmailer and xmpphp library to send jabber notifications to some actions on controller.

The problem is if something goes wrong on sending jabber message (jabber server is unavailable, username is disabled on jabber server, etc.), the web page is holded and then shows php errors code line.

The best is to run message sending to jabber, mail on console, without interapt the web page request, but how to do it in yii2?

Which errors exactly?

I am using xmpphp library, and by default connection timeout to jabber server was 30 seconds, which is php exec timeout (I figured out it after I wrote my first post).

I did like this:




try {

   $xmpp->connect(5);

   ...

   ...

}

catch (Exception $e) {

   \yii::error($e->description);

}

...



But I did the same thing with my mail sending code but page is hanged.




try {

   // sending mail code

   ...

}

catch (Exception $e) {

   \yii::error($e->description);

}

...



I think the best place of such piece of code running would be console and second process, but how to do it in yii2?

Cron + command line application. See http://stuff.cebe.cc/yii2docs/guide-console.html