Webbased chat in php without using database or file

前端 未结 14 1190
失恋的感觉
失恋的感觉 2021-02-02 14:49

I am trying to implement a realtime chat application using PHP . Is it possible to do it without using a persistent data storage like database or file . Basically what I need is

14条回答
  •  我在风中等你
    2021-02-02 15:33

    When I tried to solve the same problem, I went with Nginx's Push Module. I chose to go this way since I had to support older browsers (that usually won't support WebSockets) and had no confidence in setting up an appropriate solution like Socket.io behind a TCP proxy.

    The workflow went like this:

    1. The clients connect through long-polling to my /subscriber location, which is open to all.
    2. The /publisher location only accepts connections from my own server
    3. When a client subscribes and talks, it basically just asks a PHP script to handle whatever data is sent.
    4. This script can do validation, authorization, and such, and then forwards (via curl) the message in a JSON format to the /publisher.
    5. Nginx's Push Module handles sending the message back to the subscribers and the client establishes a new long-polling connection.

    If I had to do this all over again, then I would definitely go the Socket.io route, as it has proper fallbacks to Comet-style long-polling and has great docs for both Client and Server scripts.

    Hope this helps.

提交回复
热议问题