XMPP对于你想要做的事情可能矫枉过正。我会看看某种消息服务器。例如,对于AMQP,你可以使用:
随着STOMP,你可以使用:
显然,Zend框架有一些所谓的Zend_Queue这也可能是好的。
请参阅this question (What is a good message broker for PHP?)。
编辑:
至于为什么你要做到这一点,XMPP是相当复杂和庞大。像ActiveMQ + STOMP这样的东西要简单得多。 ActiveMQ是我使用过的唯一一个,所以我会谈论它。
要发送你会做这样的事情的消息(使用PHP Stomp):
<?
require_once("Stomp.php");
$connection = new Stomp("tcp://your-activemq-server:61613");
$connection->connect();
$connection->send("/queue/someOtherUser", "Hey buddy, let's talk.");
$connection->disconnect();
?>
然后拿起消息:
<?
require_once("Stomp.php");
$connection = new Stomp("tcp://your-activemq-server:61613");
$connection->connect();
$connection->subscribe("/queue/myQueue");
while(($message = $connection->readFrame()) != null) {
echo $message->body;
$connection->ack($message); // Tell the broker that you handled the message
}
$connection->disconnect();
?>
当然,在你可能想要一个真实的情况在发送消息之前设置一个标题来说明消息来自谁,但我不确定您在该库中发送/接收标题的方式。
更好的选择可能是打ActiveMQ directly from JavaScript。我怀疑安全性很难实现。
如果您想使用XMPP(即每个聊天记录需要某个jabber服务器上的帐户),为什么不使用像https://www.jappix.com/这样的现有解决方案?它是开源的,像一个真正的jabber客户端。 – ThiefMaster 2011-05-20 23:42:00