前回、この問題を解決するために、次のアーキテクチャを使用しました。

画像を拡大
Web サーバーは、JavaScript / jQuery またはフラッシュ チャットを提供します。
チャットが開始された後、クライアントはサーバーに新しいメッセージを 1 秒間要求します。
1 秒ポーリングの代替
それが遅い場合は、websocketsをご覧ください。
http://martinsikora.com/nodejs-and-websocket-simple-chat-tutorial
http://demo.cheyenne-server.org:8080/chat.html
しかし、Websockets は php では提供できませんでした。php + apchache agaist node.jsまたはjavaを変更する必要があります。
プレーン HTTP PHP メソッド
PHP では、サポーターからのメッセージをポーリングしてPsyBncに接続します。
PsyBncはIRCボットです。
XMPP や BitlBee に直接接続しない理由は、これらのプロトコルが PHP からのフラッピング接続、切断を好まないためです。セッションを維持することはできないため、頻繁に短い接続用に作成されたものが必要です。これが PsyBnc です。
私は次のようなものを使用します:
http://pear.php.net/package/Net_SmartIRC/download
<?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(&$irc, &$data)
{
// result is send to #smartirc-test (we don't want to spam #test)
$this->messages[] = array(
'from' => $data->nick,
'message' => $data->message,
);
}
public function get_messages() {
return $this->messages;
}
}
$bot = &new message_reader();
$irc = &new Net_SmartIRC();
$irc->setDebug(SMARTIRC_DEBUG_ALL);
$irc->setUseSockets(TRUE);
$irc->registerActionhandler(SMARTIRC_TYPE_QUERY|SMARTIRC_TYPE_NOTICE, '^' . $_SESSION['chat_id'], $bot, 'receive_messages');
$irc->connect($irc_host, $irc_port);
$irc->login($_SESSION['chat_id'], $client_name, 0, $irc_user, $irc_password);
$irc->join(array('#bitlbee'));
$irc->listen();
$irc->disconnect();
// Send new Message to supporter
if (!empty($message)) {
$irc->message(SMARTIRC_TYPE_QUERY, $_SESSION['supporter'], $message);
}
echo json_encode(array('messages' => $bot->get_messages()));
サポート インスタント メッセンジャーを PHP に接続する
PsyBnc への IRC 接続はすでに確立されています。次に、IRC から ICQ、XMPP、GOOGLE TALK、MSN、YAHOO、AOI にメッセージを送信する必要があります。
ここにBitlBeeという名前の優れたソリューションがあります。BitlBee は、ほぼすべてのインスタント メッセージ プロトコルとの間でメッセージを転送できる IRC サーバーを提供します。それらのアカウントにエイリアスを設定します。たとえば、あなたのシステムには google talk や icq で 1 つのサーバー アカウントだけが必要です。これで BitleBee はあなたのボディリストを IRC チャットとして提供します。