1

thrift .tar ファイルをダウンロードし、 lib/php/src フォルダーを取得して、名前を thrift に変更しました。次に、PHP Thrift Client を書き込むための PHP ファイルに、次のコードがあります。

<?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();

実行しようとすると、ファイルがないというエラーが表示されMyServiceます。そして、私がそれを持っていないのは正しいです。そのファイルをどこから入手できるか、またはそのようなサービスの書き方をどこから知ることができるかを知りたいです。私はApache Thriftに精通していないので、それを求めています。私が何か間違ったことをしているのか、サービスファイルを書く方法とその内容を誰かが知っているかどうか教えてください。PHP Thriftクライアントを書くだけで、ある種のコンパイラが必要になりますか?

私の質問に時間を割いていただきありがとうございます。

4

1 に答える 1

4

MyService.php を次のように取得するには、MyService.thrift IDL ファイルをthrift コンパイラでコンパイルする必要があります。

thrift --gen php MyService.thrift

このチュートリアルもご覧ください

于 2011-11-28T09:30:02.307 に答える