我安装了一个Openfire服务器,并创建了两个用户,使用XMPP协议相互聊天。
我从这里取了一个示例PHP项目:http://www.experts-exchange.com/Programming/Languages/Scripting/PHP/Q_26533833.html
这是代码片段:<?php
// activate full error reporting
//error_reporting(E_ALL & E_STRICT);
include 'XMPPHP/XMPP.php';
#Use XMPPHP_Log::LEVEL_VERBOSE to get more logging for error reports
#If this doesn't work, are you running 64-bit PHP with < 5.2.6?
$conn = new XMPPHP_XMPP('pc27', 5222, 'user1', 'user1', 'xmpphp', 'pc27', $printlog=true, $loglevel=XMPPHP_Log::LEVEL_INFO);
try {
$conn->connect();
$conn->processUntil('session_start');
$conn->presence();
$conn->message('user2@pc27', 'This is a test message!');
$conn->disconnect();
} catch(XMPPHP_Exception $e) {
die($e->getMessage());
}
但是当我点击url: localhost/Chat/sendmessage_example.php时,我在屏幕上得到以下消息:
1403610021 [INFO]: Connecting to tcp://pc27:5222 Connecting to tcp://pc27:5222 user1@pc27 1403610021 [INFO]: Starting TLS encryption
Warning: stream_socket_enable_crypto(): this stream does not support SSL/crypto in D:xampphtdocsChatXMPPHPXMPP.php on line 392
Fatal error: Maximum execution time of 30 seconds exceeded in D:xampphtdocsChatXMPPHPXMLStream.php on line 475
我尝试了什么: ini_set("max_execution_time", 300);不工作(重复出现相同的错误)。
另外,我不明白为什么它连接到"tcp://pc27:5222" ?"tcp"不应该是"localhost"或本地ip吗?
正在工作。以下是我所遵循的步骤:
1)改变了XMPPHP/XMLStream.php和XMPPHP/XMPP.php文件中"split"变为" explosion "的错误用法。
2)在Php示例中添加了300秒的超时:ini_set("max_execution_time", 300);
3)在->connect()和->processUntil()之后增加一行:$conn->presence($status='Controller available.');
4)取消xampp/php/php.ini中的注释:extension=php_openssl.dll
5)在环境变量的path变量下增加libeay32.dll的路径