registerNamespace('Thrift', 'C:\DivJava\thrift-0.11.0\lib\php\lib'); $loader->register(); // get generated client stub require_once 'php\Types.php'; require_once 'php\Test.php'; // little convenience class to workaround a visibility problem class XTestClient extends TestClient { public function __construct($arg) { parent::__construct($arg); } public function getOutput() { return $this->output_; } } use Thrift\Protocol\TBinaryProtocol; use Thrift\Transport\TBufferedTransport; use Thrift\Transport\TSocket; function getClient($host, $port) { $transport = new TSocket($host, $port); $transport->open(); return new XTestClient(new TBinaryProtocol(new TBufferedTransport($transport))); } function testFunctional($host, $port) { $client = getClient($host, $port); $a = 123; $b = 456; $c = $client->add($a, $b); echo $c . "\r\n"; $s = 'ABC'; $s2 = $client->dup($s); echo $s2 . "\r\n"; $d = new Data(array('iv' => 123, 'sv' => 'ABC')); $d2 = $client->process($d); echo sprintf('%d %s', $d2->iv, $d2->sv) . "\r\n"; $client->getOutput()->getTransport()->close(); } function testInstantiation($host, $port) { $client1 = getClient($host, $port); for($i = 0; $i < 2; $i++) { $n = $client1->getCounter(); echo $n . "\r\n"; } $client1->getOutput()->getTransport()->close(); $client2 = getClient($host, $port); for($i = 0; $i < 2; $i++) { $n = $client2->getCounter(); echo $n . "\r\n"; } $client2->getOutput()->getTransport()->close(); } define('REP', 100000); function testPerformance($host, $port) { $client = getClient($host, $port); $t1 = time(); for($i = 0; $i < REP; $i++) { $client->noop(); } $t2 = time(); echo sprintf('%d requests per second', REP / ($t2 - $t1)) . "\r\n"; } function test($lbl, $host, $port) { echo $lbl . ":\r\n"; testFunctional($host, $port); testInstantiation($host, $port); testPerformance($host, $port); } define('JAVA_HOST', 'localhost'); define('JAVA_PORT', 12345); define('DOTNET_HOST', '127.0.0.1'); // localhost did not work for me - probably some IPv4 vs IPv6 issue define('DOTNET_PORT', 12346); define('PYTHON_HOST', '127.0.0.1'); // localhost did not work for me - probably some IPv4 vs IPv6 issue define('PYTHON_PORT', 12347); test('Java', JAVA_HOST, JAVA_PORT); test('.NET', DOTNET_HOST, DOTNET_PORT); test('Python', PYTHON_HOST, PYTHON_PORT); ?>