12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152 |
- <?php
- namespace Thrift\Service;
- use Dever;
- use Thrift\Exception\TException;
- use Thrift\Factory\TFramedTransportFactory;
- use Thrift\Factory\TBinaryProtocolFactory;
- use Thrift\Factory\TTransportFactory;
- use Thrift\Factory\TBufferedTransportFactory;
- use Thrift\Server\TServerSocket;
- use Thrift\Server\TSimpleServer;
- use Thrift\Server\TForkingServer;
- use Thrift\Protocol\TBinaryProtocol;
- use Thrift\Transport\TPhpStream;
- use Thrift\Transport\TBufferedTransport;
- header('Content-Type','application/x-thrift');
- class Server extends Base
- {
- protected $processor = null;
- public function start($processor, $handle)
- {
- $this->processor = new $processor($handle);
- $this->{$this->type}();
- }
- # socket
- private function socket()
- {
- $transportFactory = new TBufferedTransportFactory();
- $protocolFactory = new TBinaryProtocolFactory(true, true);
- $transport = new TServerSocket($this->host, $this->port);
- $server = new TForkingServer($this->processor, $transport, $transportFactory, $transportFactory, $protocolFactory, $protocolFactory);
- $server->serves($this->process);
- }
- # php stream
- public function stream()
- {
- if (php_sapi_name() == 'cli') {
- echo PHP_EOL;
- }
- $transport = new TBufferedTransport(new TPhpStream(TPhpStream::MODE_R | TPhpStream::MODE_W));
- $protocol = new TBinaryProtocol($transport,true,true);
- $transport->open();
- $this->processor->process($protocol, $protocol);
- $transport->close();
- }
- }
|