1

How to get a information on the client side, without requesting the database?

The example would be a simple chat application. Two clients logged to a stream, like chat room. One filling a form, sending information by ajax to the database. Tthe other one gets it without requesting, like pushed from a event listener from the database.

Is that possible?

Many thanks.

Paul R
  • 208,748
  • 37
  • 389
  • 560
Mate
  • 51
  • 5

3 Answers3

1

It is possible to implement non-blocking I/O with PHP in a similar vein as nodejs. see: http://reactphp.org/

I would still say PHP is probably not the right tool for the job if you're just looking to make a realtime chat app. This is what nodejs excels at.

MDrollette
  • 6,887
  • 1
  • 36
  • 49
0

The HTTP layer doesn't support what you wish to accomplish. You can find more information about this in this Stackoverflow page.

You might want to use node.js and socket.io. You can also try this tutorial about creating a chat system with node.js and socket.io.

Community
  • 1
  • 1
Thomas Potaire
  • 6,166
  • 36
  • 39
0

You can pass information in-memory in server like Node.js.

Chat message would be uploaded using AJAX POST and distributed to other clients via active SSE connections (you'd have to keep track of them, e.g. in an array).

However, without a database you don't have persistency of messages. That's fine if it's OK to lose messages when clients disconnect, but in case of a chat users may expect to receive backlog of messages sent while they were offline.

Kornel
  • 97,764
  • 37
  • 219
  • 309