1
|
<?php
|
2
|
|
3
|
include_once $GLOBALS['THRIFT_ROOT'].'/server/TServer.php';
|
4
|
|
5
|
/**
|
6
|
* Simple implemtation of a Thrift server.
|
7
|
*
|
8
|
* @package thrift.server
|
9
|
*/
|
10
|
class TSimpleServer extends TServer {
|
11
|
/**
|
12
|
* Flag for the main serving loop
|
13
|
*
|
14
|
* @var bool
|
15
|
*/
|
16
|
private $stop_ = false;
|
17
|
|
18
|
/**
|
19
|
* Listens for new client using the supplied
|
20
|
* transport. It handles TTransportExceptions
|
21
|
* to avoid timeouts etc killing it
|
22
|
*
|
23
|
* @return void
|
24
|
*/
|
25
|
public function serve() {
|
26
|
$this->transport_->listen();
|
27
|
|
28
|
while (!$this->stop_) {
|
29
|
try {
|
30
|
$transport = $this->transport_->accept();
|
31
|
|
32
|
if ($transport != null) {
|
33
|
$inputTransport = $this->inputTransportFactory_->getTransport($transport);
|
34
|
$outputTransport = $this->outputTransportFactory_->getTransport($transport);
|
35
|
$inputProtocol = $this->inputProtocolFactory_->getProtocol($inputTransport);
|
36
|
$outputProtocol = $this->outputProtocolFactory_->getProtocol($outputTransport);
|
37
|
while ($this->processor_->process($inputProtocol, $outputProtocol)) { }
|
38
|
}
|
39
|
}
|
40
|
catch (TTransportException $e) { }
|
41
|
}
|
42
|
}
|
43
|
|
44
|
/**
|
45
|
* Stops the server running. Kills the transport
|
46
|
* and then stops the main serving loop
|
47
|
*
|
48
|
* @return void
|
49
|
*/
|
50
|
public function stop() {
|
51
|
$this->transport_->close();
|
52
|
$this->stop_ = true;
|
53
|
}
|
54
|
}
|