How to implement a chat room using Jquery/PHP?

前端 未结 10 1634
抹茶落季
抹茶落季 2020-12-02 07:12

I\'m looking to implement a chat room using PHP/Javascript (Jquery) with both group chat and private chat features.

The problem is how to continually update the inte

相关标签:
10条回答
  • 2020-12-02 07:27

    Polling is not a good idea. You need a solution that use long polling or web sockets.

    http://hookbox.org is probably the best tool you can use.

    It is a box that lives between the server and the browsers and manages abstractions called channels (think about an IRC channel). It is open source on github: https://github.com/hookbox/hookbox The box is written in Python but it can easily be used with a server written in any language. It also come with a Javascript library that is built on jsio (uses websockets, long-polling, or whatever is the best technology available on the browser) that guarantee that it uses the best technology available in the browsers.In a demo I saw a realtime chat implemented with few line of code.

    Hookbox’s purpose is to ease the development of real-time web applications, with an emphasis on tight integration with existing web technology. Put simply, Hookbox is a web-enabled message queue. Browers may directly connect to Hookbox, subscribe to named channels, and publish and receive messages on those channels in real-time. An external application (typically the web application itself) may also publish messages to channels by means of the Hookbox REST interface. All authentication and authorization is performed by an external web application via designated “webhook” callbacks.

    alt text

    Any time a user connects or operates on a channel, ( subscribe, publish, unsubscribe) Hookbox makes an http request to the web application for authorization for the action. Once subscribed to a channel, the user’s browser will receive real-time events that originate either in another browser via the javascript api, or from the web application via the REST api.

    They key insight is that all application development with hookbox Happens either in javascript, or in the native language of the web application itself (e.g. PHP.)

    You need a server that can run Python BUT you do NOT have to know Python.

    If instead you want to use just websockets and PHP this is good starting point: http://blancer.com/tutorials/69066/start-using-html5-websockets-today/

    0 讨论(0)
  • 2020-12-02 07:28

    I haven't done it with PHP before but you're best bet would probably be some kind of socket connection. Here's the PHP manual for sockets.

    I don't remember who's tutorial it was but I made a chat room like what you want using Flash for the client and Java for the server. I think this link might be where the tutorial was and it may help you out.

    0 讨论(0)
  • 2020-12-02 07:30

    Have you looked at PHPDaemon, which is written with active usage of libevent and pnctl? It has lots of features and even simple chat demo application. Even it has some production implementations.

    0 讨论(0)
  • 2020-12-02 07:38

    this could be a good starting point

    http://css-tricks.com/jquery-php-chat/

    0 讨论(0)
  • 2020-12-02 07:40

    This looks promising! Might even be super easy to restyle :)

    http://www.php-development.ru/javascripts/ajax-chat.php

    Ajax Chat script in Javascript/PHP

    Description

    Ajax Chat is a light-weight customizable web chat software implemented in JavaScript and PHP. The script does not require Java, Flash, or any other plugins.

    Features

    • Public and private chat.
    • Login as a registered user or as a guest.
    • Away status, custom colors, smileys, user gender/status icons.
    • Ajax Chat can be integrated with a third-party membership system by implementing user authentication routine. Advanced integration options: if user is logged in to the website, he can be logged in to the chat automatically.

    Ajax lightweight chat script

    *Please note that this is a copy/paste from the original site.

    0 讨论(0)
  • 2020-12-02 07:43

    I believe the problem you are looking at requires the use of comet web programming. You can find more details on wikipedia, by searching for Comet programming, and on Ajaxian (I'm still new to this site and I can't post more than 1 link in the response).

    The problem is that this can't be easily achieved with php on the server side. More details: using comet with php

    Also, if you search on google for 'php comet' you'll find a tutorial to achieve the desired effect.

    LATER EDIT

    Ape project

    Implemented a project using this engine. Is great.

    Comet with php

    Hope this helps, Gabriel

    0 讨论(0)
提交回复
热议问题