Reputation: 4267
I have downloaded thrift .tar file and took lib/php/src folder and I renamed it as thrift . Then in my PHP file to write PHP Thrift Client , I have following 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',1100);
$transport->open();
$protocol = new TBinaryProtocol($transport);
$client= new MyServiceClient($protocol, $protocol);
$result = $client->operation('param1', 'param2');
Print 'result = ' . $result;
$transport->close();
When I tried to execute it , it give error that I don't have MyService
files. And it is correct I don't have that. I want to know that from where I can get that file or from where I can know how to write such service. I am asking that because I am not well versed with Apache Thrift. Please tell if I am doing some thing wrong or if any one knows how I can write service file and what will be in it? Will there be some sort of compiler required for just writing PHP Thrift client?
Please tell whatever you know , thanks for giving some time to my question.
Upvotes: 1
Views: 2467
Reputation: 4392
You need to compile MyService.thrift IDL file with thrift compiler to get MyService.php something like this:
thrift --gen php MyService.thrift
please also take a look at this tutorial
Upvotes: 4