THRIFT-778. php: PHP socket listening server

This patch which adds TServerTransport/TServerSocket, along with a generic TServer and TSimpleServer implementation.

Patch: Nick Jones

git-svn-id: https://svn.apache.org/repos/asf/incubator/thrift/trunk@984864 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/lib/php/src/server/TSimpleServer.php b/lib/php/src/server/TSimpleServer.php
new file mode 100644
index 0000000..f7d0a32
--- /dev/null
+++ b/lib/php/src/server/TSimpleServer.php
@@ -0,0 +1,54 @@
+<?php
+
+include_once $GLOBALS['THRIFT_ROOT'].'/server/TServer.php';
+
+/**
+ * Simple implemtation of a Thrift server.
+ *
+ * @package thrift.server
+ */
+class TSimpleServer extends TServer {
+  /**
+   * Flag for the main serving loop
+   *
+   * @var bool
+   */
+  private $stop_ = false;
+
+  /**
+   * Listens for new client using the supplied
+   * transport. It handles TTransportExceptions
+   * to avoid timeouts etc killing it
+   *
+   * @return void
+   */
+  public function serve() {
+    $this->transport_->listen();
+
+    while (!$this->stop_) {
+      try {
+        $transport = $this->transport_->accept();
+        
+        if ($transport != null) {
+          $inputTransport = $this->inputTransportFactory_->getTransport($transport);
+          $outputTransport = $this->outputTransportFactory_->getTransport($transport);
+          $inputProtocol = $this->inputProtocolFactory_->getProtocol($inputTransport);
+          $outputProtocol = $this->outputProtocolFactory_->getProtocol($outputTransport);
+          while ($this->processor_->process($inputProtocol, $outputProtocol)) { }
+        }
+      }
+      catch (TTransportException $e) { }
+    }
+  }
+
+  /**
+   * Stops the server running. Kills the transport
+   * and then stops the main serving loop
+   *
+   * @return void
+   */
+  public function stop() {
+    $this->transport_->close();
+    $this->stop_ = true;
+  }
+}