-1

I have web application written in PHP, I want to build a Real-time chat module for my web app, I want to use firebase, but I am not able to figure out how to build a chat with fir-base and PHP so all my user can chat one to one, tough I have idea that I have to sync all my users to firebase database to enable chat between them, but how it will work with PHP. If someone has done this before, pleas help me out. Here's what I found on codelab, but it for node.js only can someone suggest me how to do it with php?

https://codelabs.developers.google.com/codelabs/firebase-web/#0

KENdi
  • 7,576
  • 2
  • 16
  • 31
Mohd Sadiq
  • 181
  • 1
  • 2
  • 16

2 Answers2

1

You can use Firebase PHP Client which is based on the Firebase REST API.

For websocket, use Ratchet. Ratchet is a loosely coupled PHP library providing developers with tools to create real time, bi-directional applications between clients and servers over WebSockets.

Hasan Shahriar
  • 468
  • 3
  • 11
1

I suppose you're talking about Firebase because you need to persist some data. Firebase is a solution among others.

So I'll suppose you need data persistence to keep a chat history. If not, then it's an XY problem: you should explain what is your first need without talking about any solution.

By using only a websocket server, you should be able to mount a chat server, no need for database. You can see multiple chat server example on the web, but RatchetPHP (http://socketo.me/docs/hello-world) is a good solution. Also see the reddit topic for some other solutions: https://www.reddit.com/r/PHP/comments/5unai8/ratchet_php_websockets/

But if you need history, you can persist it in either a database or only a simple log file, depending on if you need to do some fetch, sort, aggregation operations.

Or, if you just need a chat module for your website, a simpler solution is to embed an IRC widget: https://kiwiirc.com/embedding

Alcalyn
  • 1,531
  • 14
  • 25