Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Last time i have to solve this problem i used this architecture:</p> <p><img src="https://i.stack.imgur.com/DROaB.png" alt="enter image description here"></p> <p><a href="http://i48.tinypic.com/wgu81g.png" rel="nofollow noreferrer">Entlarge image</a></p> <p>The Webserver provides an JavaScript / jQuery or flash chat.</p> <p>After chat is started, the client ask the server all 1 Second for new Messages.</p> <h2>Alternative for 1 Sec Polling</h2> <p>If that is to slow for you, have a look at <a href="http://en.wikipedia.org/wiki/WebSocket" rel="nofollow noreferrer">websockets</a>.</p> <p><a href="http://martinsikora.com/nodejs-and-websocket-simple-chat-tutorial" rel="nofollow noreferrer">http://martinsikora.com/nodejs-and-websocket-simple-chat-tutorial</a></p> <p><a href="http://demo.cheyenne-server.org:8080/chat.html" rel="nofollow noreferrer">http://demo.cheyenne-server.org:8080/chat.html</a></p> <p>But Websockets could no provided by php. There for you need to change php + apchache agaist <a href="http://nodejs.org/" rel="nofollow noreferrer">node.js</a> or <a href="https://github.com/TooTallNate/Java-WebSocket" rel="nofollow noreferrer">java</a>.</p> <h2>Plain HTTP PHP Methode</h2> <p>In PHP you will connect to the <a href="http://www.psybnc.at/" rel="nofollow noreferrer">PsyBnc</a> with is polling the messages from the supporter for you. The <a href="http://en.wikipedia.org/wiki/BNC_%28software%29" rel="nofollow noreferrer">PsyBnc</a> is an <a href="http://www.cse.ohio-state.edu/cgi-bin/rfc/rfc1459.html" rel="nofollow noreferrer">IRC</a> bot. The reason why dont directly connect to XMPP or BitlBee is that those protocols dont like the flapping connect, disconenct from PHP. Because you can not keep the session allive, you need something that is made for offten and short connects. This is the PsyBnc.</p> <p>I would use something like this:</p> <p><a href="http://pear.php.net/package/Net_SmartIRC/download" rel="nofollow noreferrer">http://pear.php.net/package/Net_SmartIRC/download</a></p> <pre><code>&lt;?php session_start(); $message = $_GET['message']; $client_name = $_GET['client_name']; if (empty($_SESSION['chat_id'])) { $_SESSION['chat_id'] = md5(time(). mt_rand(0, 999999)); } if (empty($_SESSION['supporter'])) { // how do you select the supporter? // only choose a free? // We send first message to all supporter and the first who grapped got the chat (where only 3 gues) } $irc_host = "127.0.0.1"; $irc_port = 6667; // Port of PsyBnc $irc_password = "password_from_psy_bnc"; $irc_user = "username_from_psy_bnc"; include_once('Net/SmartIRC.php'); class message_reader { private $messages = array(); public function receive_messages(&amp;$irc, &amp;$data) { // result is send to #smartirc-test (we don't want to spam #test) $this-&gt;messages[] = array( 'from' =&gt; $data-&gt;nick, 'message' =&gt; $data-&gt;message, ); } public function get_messages() { return $this-&gt;messages; } } $bot = &amp;new message_reader(); $irc = &amp;new Net_SmartIRC(); $irc-&gt;setDebug(SMARTIRC_DEBUG_ALL); $irc-&gt;setUseSockets(TRUE); $irc-&gt;registerActionhandler(SMARTIRC_TYPE_QUERY|SMARTIRC_TYPE_NOTICE, '^' . $_SESSION['chat_id'], $bot, 'receive_messages'); $irc-&gt;connect($irc_host, $irc_port); $irc-&gt;login($_SESSION['chat_id'], $client_name, 0, $irc_user, $irc_password); $irc-&gt;join(array('#bitlbee')); $irc-&gt;listen(); $irc-&gt;disconnect(); // Send new Message to supporter if (!empty($message)) { $irc-&gt;message(SMARTIRC_TYPE_QUERY, $_SESSION['supporter'], $message); } echo json_encode(array('messages' =&gt; $bot-&gt;get_messages())); </code></pre> <h2>Connect the support instant messanger to PHP</h2> <p>We have allready an IRC connection to the PsyBnc, now we need to send messages from IRC to ICQ, XMPP, GOOGLE TALK, MSN, YAHOO, AOI...</p> <p>Here for is a nice solution named <a href="http://www.bitlbee.org/main.php/news.r.html" rel="nofollow noreferrer">BitlBee</a>. BitlBee offers an IRC Server with can transfer message from and to nearly all instant messager protocols. By aliasing those accounts. For example you need for your system only 1 Server account at google talk, icq ... and at all your supporter to the buddylist of those accounts. Now BitleBee will provide your <a href="http://www.youtube.com/watch?v=0qqoM_kKFuk" rel="nofollow noreferrer">boddylist</a> as an irc chat.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload