Solved thread

This post is marked as solved. If you think the information contained on this thread must be part of the official documentation, please contribute submitting a pull request to its repository.

Phalcon and websockets


Since there is no real websocket implementation in phalcon I'm trying to use a very simple php websocket library that i wrote some time ago. But since i'm new to phalcon I find it hard to know how to correctly make the sockets available in phalcon using the correct methods.

I've been looking at the webird project, but that is more of a spin off framework of phalcon, it does use Ratchet ( but it is such a big implementation using sevral sub libraries (react).

My question is, how to register my classes (websocketCOnnect, websocket and websocketHelper (extends websocket) ) to the phalcon project using the supplied phalcon methodoligy.

I guess I can use a dispacher to register the service and use eventsManager to manage data and actions. But I don't know if this is the correct way to do it. Even if it is the correct way, beeing new to phalcon I'm not sure how to implement it. Is there any similar projects using some kind of streams(?) that i can take a look at, just to see how they are implemented the phalcon way? :)

Regards André

edited Dec '15

Why you even want to use websockets in php ? Its the worst thing you can do to be honest. Php is not for such a thing, use javascript(node). You can register them just by using loader, and then use them however you like.

Hi and thanks for your answer.

I wouldn't go as far as saying its the worst withng :), bur you are right, for most chat/board systems nodejs is a great choice. But for the current project i need a websocket server that that accepts UDP connections, and as far as i know javascript can not do that.

Also i like to keep things clean and I wouldn't personally mix different frameworks unless it is really necessary. :)

Loading the classes might be the trick. Any idea, how do broadcast the recieved message to the MVCs in the proper way?

Cheers André

edited Dec '15

I think you would need cli phalcon application, phalcon works on HTTP and router. You would need to write some adapter ono php side which would take websocket message, create phalcon application and then somehow parse this message to some phalcon route and then you get resonse from phalcon and return broadcast this response to all clients/whatever.

Its just simpler to use node for all websocket communication and call php cli for all application logic if you still wanna use php.

Thank you @Jurigag.

The phalcon cli would accually work as I would like to. I'm going to try implementeing that.

edited Jul '16

I recently posted this on another thread so I'll just paste it to here. I did lots of work with Phalcon, Ratchet and Webpack integration. What you want is Ratchet and possibly Thruway.

I've done this in my Webird skeleton project. It is a heavily modified Vokuro system with a deep Webpack integration.

I haven't worked with these for about half of a year now and I just set it up to do a proof of concept. I'm doing other things and in several months I'll be working with Thruway so that I can use the WAMP protocol. Thruway uses Ratchet.