PHP Thrift client

Directory structure

  • <php library root>
    • thrift
      • packages
        • <contents of php_gen>
      • protocol
        • TBinaryProtocol.php
        • TProtocol.php
      • transport
        • TBufferedTransport.php
        • TFramedTransport.php
        • THttpClient.php
        • TMemoryBuffer.php
        • TNullTransport.php
        • TPhpStream.php
        • TSocket.php
        • TSocketPool.php
        • TTransport.php
      • autoload.php
      • Thrift.php

PHP config

  • Add <php library root> to include_path.

PHP code

<?php
$GLOBALS['THRIFT_ROOT'] = 'thrift';

require_once 'thrift/Thrift.php';
require_once 'thrift/transport/TTransport.php';
require_once 'thrift/transport/TSocket.php';
require_once 'thrift/protocol/TBinaryProtocol.php';
require_once 'thrift/transport/TFramedTransport.php';
require_once 'thrift/transport/TBufferedTransport.php';

require_once 'thrift/packages/MyService/MyService.php';
require_once 'thrift/packages/MyService/MyService_types.php';

$transport = new TSocket('localhost', 7911);
$transport->open();

$protocol = new TBinaryProtocol($transport);

$client= new MyServiceClient($protocol, $protocol);

$result = $client->operation('param1', 'param2');

Print 'result = ' . $result;

$transport->close();
?>

PHP Notes

  • Sets must be of primitives, not structs. If you're getting an error like this, it's because of that. Switch from a Set to a List.
 $this->success[$elem40] = true; It says "illegal offset type" 
  • No labels