简体   繁体   中英

Problems implementing a PHP Thrift server

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM