THRIFT-404. php: Make TPhpStream work for cli (cgi) scripts


git-svn-id: https://svn.apache.org/repos/asf/incubator/thrift/trunk@758526 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/lib/php/src/transport/TPhpStream.php b/lib/php/src/transport/TPhpStream.php
index 9a3049a..9b8de82 100644
--- a/lib/php/src/transport/TPhpStream.php
+++ b/lib/php/src/transport/TPhpStream.php
@@ -36,7 +36,7 @@
 
   public function open() {
     if ($this->read_) {
-      $this->inStream_ = @fopen('php://input', 'r');
+      $this->inStream_ = @fopen(self::inStreamName(), 'r');
       if (!is_resource($this->inStream_)) {
         throw new TException('TPhpStream: Could not open php://input');
       }
@@ -88,6 +88,13 @@
     @fflush($this->outStream_);
   }
 
+  private static function inStreamName() {
+    if (php_sapi_name() == 'cli') {
+      return 'php://stdin';
+    }
+    return 'php://input';
+  }
+
 }
 
 ?>