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

Phalcon and Socket.io

I want to try socket.io for the first time. I did the tutorial chat message with socket.io. But now I want to select some data in my database to count the number of rows in the table 'product' with query Phalcon :

$count_products = Product::count();

For example in my HTML page I have 5 products and when I'll add one product or more into my table Product I want an auto refresh to see 6 products in my HTML page.

I need to do an query to my database with phalcon and push to socket.io the data to do a realtime update.

could you help me to do that and tell me if socket.io is the best tools to conncect web socket with phalcon ?



85.5k

i havent used socket io with php i guess you need this: https://github.com/wisembly/elephant.io

but when i need sockets with php i use ratchet. https://socketo.me/

so if you got the idea of sockets with those 2 you can do this stuff easily ( but time consumingly :D )

edited Jun '16

You realize that socket.io is nodejs server, and you have client lib written in js which handles client communication? Phalcon is by chance also server side application stack. So, it depends what you want to achieve.

Client -> Socket.io -> Phalcon

edited Jun '16

You are bascially describing any pub system out their. you can bascially insert any 3 peices into this puzzle and you can achieve this...

Stamster is right with the exception of the way the graph looks.

Client(browser) <-> MessageQueuePubSub(Socket.io) <-> Rest APi for data?(Phalcon).

You realize that socket.io is nodejs server, and you have client lib written in js which handles client communication? Phalcon is by chance also server side application stack. So, it depends what you want to achieve.

Client -> Socket.io -> Phalcon

you will post updates to the message queue from both ends, and list fro updates at both ends. Socket.io is nothing more than a message broker.

Socket.io will sit their and listen for messages on its channels. when a message happens you logic inside socket io will tell it what to do with those messages. Be it distribute those messages to listening subscribers or any other system. Asking if "X" is the best thing to do it with, wiht ushc little context is a bad question.

If all you are doing is retrieving and updateing data from a datbase why choose phalcon ?

What are you using for your UI on the fornt end?

You could acheive the same result with a 2 part system using React + firebase for instance.

Without more details on your contraints its hard to say what is the "Best" tool for the job.