123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960 |
- <?php
- namespace Thrift\Service;
- use Dever;
- use Thrift\Transport\TPhpStream;
- use Thrift\Protocol\TBinaryProtocol;
- use Thrift\Transport\TSocket;
- use Thrift\Transport\TBufferedTransport;
- use Thrift\Transport\THttpClient;
- use Thrift\Exception\TException;
- class Client extends Base
- {
- public function get($client, $callback, $param)
- {
- $socket = $this->{$this->type}();
- $transport = new TBufferedTransport($socket, 1024, 1024);
- $protocol = new TBinaryProtocol($transport);
- $client = new $client($protocol);
- $transport->open();
- array_unshift($param, $client);
- $result = call_user_func_array($callback, $param);
- //同步方式进行交互
- /*
- $recv = $client->sayHello('Courages');
- echo "\n sayHello11dd:".$recv." \n";
- //异步方式进行交互
- /*
- $client->send_sayHello('Us');
- echo "\n send_sayHello \n";
- $recv = $client->recv_sayHello();
- echo "\n recv_sayHello:".$recv." \n";
- */
- $transport->close();
- return $result;
- }
- private function socket()
- {
- return new TSocket($this->host, $this->port);
- }
- public function stream()
- {
- return new TPhpStream(TPhpStream::MODE_R | TPhpStream::MODE_W);
- }
- public function http()
- {
- return new THttpClient($this->host, $this->port, '/server.php');
- }
- }
|