1

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.

hakre
  • 178,314
  • 47
  • 389
  • 754
Blates
  • 69
  • 7
  • Are you getting any error message or what does not work specifically? – hakre Feb 22 '12 at 19:25
  • You might also check out this question: http://stackoverflow.com/questions/8871858/is-it-possible-to-use-apache-thrift-on-a-regular-web-server – Will Warren May 30 '12 at 15:26

1 Answers1

0

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

Electronick
  • 1,113
  • 8
  • 14