实现PHP Thrift服务器的问题


Problems implementing a PHP Thrift server

我目前正在尝试创建一个PHP Thrift服务器,PHP客户端将访问该服务器来执行两个整数的加法。这只是一个基本的实现,可以让Thrift客户端/服务器的基本功能发挥作用,但我并不完全清楚如何设置PHP服务器端。这是在AmazonEC2localhost上完成的。对不起,我的单词测试变体用完了。

这是基本的Thrift IDL-http://pastebin.com/3KGGrDUN

namespace php gaybear
service addTest {
void ping(),
i32 add(1:i32 num1, 2:i32 num2),
}

这是目前服务器端的代码-http://pastebin.com/CWnernxf

<?
$GLOBALS['THRIFT_ROOT'] = '/usr/lib/php';
require_once $GLOBALS['THRIFT_ROOT'].'/Thrift.php';
require_once $GLOBALS['THRIFT_ROOT'].'/protocol/TBinaryProtocol.php';
require_once $GLOBALS['THRIFT_ROOT'].'/transport/TPhpStream.php';
require_once $GLOBALS['THRIFT_ROOT'].'/transport/TBufferedTransport.php';
$GEN_DIR = '/usr/lib/php/gen-php/gaybear/';
require_once $GEN_DIR.'/addTest.php';
require_once $GEN_DIR.'/gaybear_types.php';
class addHandler {
        public function ping() {
        }
        public function add($num1, $num2) {
                return $num1 + $num2;
        }
        public function zip() {
        }
}
$handler = new addHandler();
$processor = new addTest($handler);
$transport = new TBufferedTransport(new TPhpStream(TPhpStream::MODE_R | TPhpStream::MODE_W));
$protocol = new TBinaryProtocol($transport, true, true);
$transport->open();
$processor->process($protocol, $protocol);
$transport->close();
?>

我不知道你是如何设置服务器端的。对于其他语言来说,它似乎就像定义一个套接字一样简单,但从阅读许多教程来看,PHP似乎使用了"TPhpStream"。

有没有人能为创建Thrift PHP服务器并让PHP客户端从中调用基本过程提供一些线索?我还没有找到一个教程能够很好地解释Thrift PHP服务器的创建,让我理解。

谢谢。

不是英语,而是很多代码示例,您可以尝试使用谷歌翻译。

http://www.easy-coding.de/wiki/php/thrift-php-server.html