实现 PHP Thrift 服务器的问题
我目前正在尝试创建一个 PHP Thrift 服务器,PHP 客户端将访问该服务器以执行两个整数的加法。只是一个基本的实现,让 Thrift 客户端/服务器的基础知识正常工作,但我并不完全清楚如何设置 PHP 服务器端。这是在 Amazon EC2 本地主机上完成的。请原谅事物的名称——我已经用完了“测试”一词的变体。
这是基本的 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 服务器的创建,让我能够理解。
谢谢。
I'm currently trying to create a PHP Thrift server which will be accessed by a PHP client to perform addition of two integers. Just a basic implementation to get the basics of a Thrift client/server working, but I'm not totally clear on how to set up the PHP server side of things. This is being done on Amazon EC2 localhost. Excuse the names of things - I ran out of variations of the word test.
This is the basic Thrift IDL - http://pastebin.com/3KGGrDUN
namespace php gaybear
service addTest {
void ping(),
i32 add(1:i32 num1, 2:i32 num2),
}
This is currently the code for the server side of things - 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();
?>
I'm not sure how you go about setting up the server side of things. For other languages it seems to be as simple as defining a socket, but from reading many tutorials PHP seems to use "TPhpStream".
Is there anyone that could shed some light into creating a Thrift PHP server and getting a PHP client to call basic procedures from it? I haven't found a tutorial that has explained the creation of Thrift PHP server well enough for me to understand.
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不是英文的,但是有很多代码示例,你可以尝试使用谷歌翻译。
http://www.easy-coding.de/wiki/php /thrift-php-server.html
Not in English, but much code samples and you can try to use Google translate.
http://www.easy-coding.de/wiki/php/thrift-php-server.html