简体   繁体   English

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

[英]Thrift service for PHP based Thrift Client

I have downloaded thrift .tar file and took lib/php/src folder and I renamed it as thrift . 我已经下载了thrift .tar文件并使用了lib / php / src文件夹并将其重命名为thrift。 Then in my PHP file to write PHP Thrift Client , I have following code: 然后在我的PHP文件中编写PHP Thrift Client,我有以下代码:

<?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. 当我尝试执行它时,它给出了我没有MyService文件的错误。 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. 我问这是因为我不熟悉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? 编写PHP Thrift客户端是否需要某种编译器?

Please tell whatever you know , thanks for giving some time to my question. 请告诉你知道的任何事情,谢谢你给我一些时间来解决我的问题。

You need to compile MyService.thrift IDL file with thrift compiler to get MyService.php something like this: 您需要使用thrift编译器编译MyService.thrift IDL文件以获取MyService.php,如下所示:

thrift --gen php MyService.thrift

please also take a look at this tutorial 另请参阅本教程

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM