Add options to thrift transport classes for custom error handlers

Summary: So we can pass debug_rlog (facebook custom) in as a handler for errors to thrift (generic open source)

Reviewed By: lucas


git-svn-id: https://svn.apache.org/repos/asf/incubator/thrift/trunk@664903 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/lib/php/src/transport/TSocket.php b/lib/php/src/transport/TSocket.php
index 3dc643c..c193305 100644
--- a/lib/php/src/transport/TSocket.php
+++ b/lib/php/src/transport/TSocket.php
@@ -65,16 +65,28 @@
   private $debug_ = FALSE;
 
   /**
+   * Debug handler
+   *
+   * @var mixed
+   */
+  private $debugHandler_ = null;
+
+  /**
    * Socket constructor
    *
-   * @param string $host    Remote hostname
-   * @param int    $port    Remote port
-   * @param bool   $persist Whether to use a persistent socket
+   * @param string $host         Remote hostname
+   * @param int    $port         Remote port
+   * @param bool   $persist      Whether to use a persistent socket
+   * @param string $debugHandler Function to call for error logging
    */
-  public function __construct($host='localhost', $port=9090, $persist=FALSE) {
+  public function __construct($host='localhost',
+                              $port=9090,
+                              $persist=FALSE,
+                              $debugHandler=null) {
     $this->host_ = $host;
     $this->port_ = $port;
     $this->persist_ = $persist;
+    $this->debugHandler_ = $debugHandler ? $debugHandler : 'error_log';
   }
 
   /**
@@ -135,7 +147,7 @@
     if ($this->handle_ === FALSE) {
       $error = 'TSocket: Could not connect to '.$this->host_.':'.$this->port_;
       if ($this->debug_) {
-        error_log($error);
+        $this->debugHandler_($error);
       }
       throw new Exception($error);
     }