如何使用PHP连接到XMPP服务器

lee*_*hin 11 php xmpp openfire

我已经设置了一个XMPP服务器,我已经创建了登录表单.PHP和HTML.我之前没有这样做,我想知道如何通过PHP连接到XMPP服务器,就像使用PHP连接到MySQL一样.

小智 3

<?php 
set_time_limit(0);  // some time connection take while  
require_once 'xmpp-lib/XMPPHP/XMPP.php';  
$host = 'you Host name'; // ex.192.168.2.1  
$port = '5222'; // its defauls xmpp port 
$username = 'name@host' // ex vivek@host 
$pass = 'userpass';  
$conn = new XMPPHP_XMPP(host , $port, $username, $pass, 'xmpphp','yourhost', $printlog=false, $loglevel=XMPPHP_Log::LEVEL_INFO);  
try {
         $conn->connect();
         $conn->processUntil('session_start');
         $conn->presence();
         $conn->message('anotherusername@host', 'Hello!');
         $conn->disconnect(); 
} catch(XMPPHP_Exception $e) {
         die($e->getMessage()); 
} 
?>`enter code here`
Run Code Online (Sandbox Code Playgroud)

  • 是否可以将xmpp协议与php web服务集成以通过tcp/ip协议传递数据? (2认同)