2011-11-24 112 views
1

我已经下载了thrift .tar文件,并将lib/php/src文件夹下载,并将其重命名为thrift。然后在我的PHP文件编写PHP节俭的客户,我有下面的代码:基于PHP的Thrift客户端的节俭服务

<?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

您需要编译MyService.thrift IDL文件,勤俭节约的编译器得到MyService.php是这样的:

thrift --gen php MyService.thrift

也请看一看this tutorial

相关问题