THRIFT-404. php: Make TPhpStream work for cli (cgi) scripts
authorDavid Reiss <dreiss@apache.org>
Thu, 26 Mar 2009 06:14:45 +0000 (06:14 +0000)
committerDavid Reiss <dreiss@apache.org>
Thu, 26 Mar 2009 06:14:45 +0000 (06:14 +0000)
git-svn-id: https://svn.apache.org/repos/asf/incubator/thrift/trunk@758526 13f79535-47bb-0310-9956-ffa450edef68

lib/php/src/transport/TPhpStream.php

index 9a3049a..9b8de82 100644 (file)
@@ -36,7 +36,7 @@ class TPhpStream extends TTransport {
 
   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 @@ class TPhpStream extends TTransport {
     @fflush($this->outStream_);
   }
 
+  private static function inStreamName() {
+    if (php_sapi_name() == 'cli') {
+      return 'php://stdin';
+    }
+    return 'php://input';
+  }
+
 }
 
 ?>