We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

Save websocket message in database

Hi guys, I'm writing a cli project with Phalcon.

I'm using websockets and made a common/library/Chat.php implementing Ratchet\MessageComponentInterface.

I'd like to save the messages I receive (and send) to my database (model is in common/models/Message.php). Where is the best place to do it ?

Directly in the library/Chat.php or in a Task ? And if it is in a Task, how do I call it from library/Chat.php ?

In a place where you dispatch all your messages, i.e. some central controller logic? Just instantiate your model there and fire save().