dsh102123 2011-11-24 23:56
浏览 73

基于PHP的Thrift客户端的节俭服务

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.

  • 写回答

1条回答 默认 最新

  • douyan1244 2011-11-28 09:30
    关注

    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

    评论

报告相同问题?

悬赏问题

  • ¥15 C++使用Gunplot
  • ¥15 这个电路是如何实现路灯控制器的,原理是什么,怎么求解灯亮起后熄灭的时间如图?
  • ¥15 matlab数字图像处理频率域滤波
  • ¥15 在abaqus做了二维正交切削模型,给刀具添加了超声振动条件后输出切削力为什么比普通切削增大这么多
  • ¥15 ELGamal和paillier计算效率谁快?
  • ¥15 file converter 转换格式失败 报错 Error marking filters as finished,如何解决?
  • ¥15 Arcgis相交分析无法绘制一个或多个图形
  • ¥15 关于#r语言#的问题:差异分析前数据准备,报错Error in data[, sampleName1] : subscript out of bounds请问怎么解决呀以下是全部代码:
  • ¥15 seatunnel-web使用SQL组件时候后台报错,无法找到表格
  • ¥15 fpga自动售货机数码管(相关搜索:数字时钟)