Francesco
Francesco

Reputation: 25259

Can I use webSockets on my php web app?

I'm running a simple web app on my server It's a Mediatemple Ubuntu, PHP, apache, mysql semi-pro server so i can install whatever i want.

My app is simple, imagine a list of items. and users that can add more items to this list. I'd love to refresh in real time, like a chat.

I'm running a simple setInterval with ajax on javascript but it seems not an elegant solution...

Can I install nodejs / socket.io or... what else can i do?

Upvotes: 0

Views: 184

Answers (1)

stolli
stolli

Reputation: 5946

There's no reason why you can't implement WebSockets in PHP. Apache and PHP will certainly handle a socket-type connection. You won't use node (I mean you could, but why complicate your environment), you would use something like ratchet or another PHP socket library. Then use socket.io on the client side to make/maintain the connection.

You will also need some sort of event emitting solution in your server-side, such as Kafka, to get the data that has been updated. This can get complicated quickly, but it's totally doable.

Upvotes: 1

Related Questions