| Mark Slee | 6e53644 | 2006-06-30 18:28:50 +0000 | [diff] [blame] | 1 | <?php | 
| David Reiss | ea2cba8 | 2009-03-30 21:35:00 +0000 | [diff] [blame] | 2 | /* | 
 | 3 |  * Licensed to the Apache Software Foundation (ASF) under one | 
 | 4 |  * or more contributor license agreements. See the NOTICE file | 
 | 5 |  * distributed with this work for additional information | 
 | 6 |  * regarding copyright ownership. The ASF licenses this file | 
 | 7 |  * to you under the Apache License, Version 2.0 (the | 
 | 8 |  * "License"); you may not use this file except in compliance | 
 | 9 |  * with the License. You may obtain a copy of the License at | 
| Mark Slee | 4902c05 | 2007-03-01 00:31:30 +0000 | [diff] [blame] | 10 |  * | 
| David Reiss | ea2cba8 | 2009-03-30 21:35:00 +0000 | [diff] [blame] | 11 |  *   http://www.apache.org/licenses/LICENSE-2.0 | 
 | 12 |  * | 
 | 13 |  * Unless required by applicable law or agreed to in writing, | 
 | 14 |  * software distributed under the License is distributed on an | 
 | 15 |  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | 
 | 16 |  * KIND, either express or implied. See the License for the | 
 | 17 |  * specific language governing permissions and limitations | 
 | 18 |  * under the License. | 
| Mark Slee | 4902c05 | 2007-03-01 00:31:30 +0000 | [diff] [blame] | 19 |  * | 
 | 20 |  * @package thrift.transport | 
| Mark Slee | 4902c05 | 2007-03-01 00:31:30 +0000 | [diff] [blame] | 21 |  */ | 
 | 22 |  | 
| David Reiss | ea2cba8 | 2009-03-30 21:35:00 +0000 | [diff] [blame] | 23 |  | 
| Mark Slee | 4902c05 | 2007-03-01 00:31:30 +0000 | [diff] [blame] | 24 | /** | 
| Mark Slee | 6e53644 | 2006-06-30 18:28:50 +0000 | [diff] [blame] | 25 |  * Sockets implementation of the TTransport interface. | 
 | 26 |  * | 
 | 27 |  * @package thrift.transport | 
| Mark Slee | 6e53644 | 2006-06-30 18:28:50 +0000 | [diff] [blame] | 28 |  */ | 
 | 29 | class TSocket extends TTransport { | 
 | 30 |  | 
 | 31 |   /** | 
 | 32 |    * Handle to PHP socket | 
 | 33 |    * | 
 | 34 |    * @var resource | 
 | 35 |    */ | 
 | 36 |   private $handle_ = null; | 
 | 37 |  | 
 | 38 |   /** | 
 | 39 |    * Remote hostname | 
| Mark Slee | 0cdc6c8 | 2007-11-13 10:19:08 +0000 | [diff] [blame] | 40 |    * | 
| Mark Slee | 6e53644 | 2006-06-30 18:28:50 +0000 | [diff] [blame] | 41 |    * @var string | 
 | 42 |    */ | 
| Mark Slee | ade2c83 | 2006-09-08 03:41:50 +0000 | [diff] [blame] | 43 |   protected $host_ = 'localhost'; | 
| Mark Slee | 6e53644 | 2006-06-30 18:28:50 +0000 | [diff] [blame] | 44 |  | 
 | 45 |   /** | 
 | 46 |    * Remote port | 
 | 47 |    * | 
 | 48 |    * @var int | 
 | 49 |    */ | 
| Mark Slee | ade2c83 | 2006-09-08 03:41:50 +0000 | [diff] [blame] | 50 |   protected $port_ = '9090'; | 
 | 51 |  | 
 | 52 |   /** | 
 | 53 |    * Send timeout in milliseconds | 
 | 54 |    * | 
 | 55 |    * @var int | 
 | 56 |    */ | 
 | 57 |   private $sendTimeout_ = 100; | 
 | 58 |  | 
 | 59 |   /** | 
 | 60 |    * Recv timeout in milliseconds | 
 | 61 |    * | 
 | 62 |    * @var int | 
 | 63 |    */ | 
 | 64 |   private $recvTimeout_ = 750; | 
 | 65 |  | 
 | 66 |   /** | 
 | 67 |    * Is send timeout set? | 
 | 68 |    * | 
 | 69 |    * @var bool | 
 | 70 |    */ | 
 | 71 |   private $sendTimeoutSet_ = FALSE; | 
| Mark Slee | 6e53644 | 2006-06-30 18:28:50 +0000 | [diff] [blame] | 72 |  | 
 | 73 |   /** | 
 | 74 |    * Persistent socket or plain? | 
 | 75 |    * | 
 | 76 |    * @var bool | 
 | 77 |    */ | 
| Mark Slee | ade2c83 | 2006-09-08 03:41:50 +0000 | [diff] [blame] | 78 |   private $persist_ = FALSE; | 
 | 79 |  | 
 | 80 |   /** | 
 | 81 |    * Debugging on? | 
 | 82 |    * | 
 | 83 |    * @var bool | 
 | 84 |    */ | 
| robert | b0fac3e | 2007-01-15 23:53:25 +0000 | [diff] [blame] | 85 |   protected $debug_ = FALSE; | 
| Mark Slee | 6e53644 | 2006-06-30 18:28:50 +0000 | [diff] [blame] | 86 |  | 
 | 87 |   /** | 
| Mark Slee | ad58f95 | 2007-01-03 19:23:50 +0000 | [diff] [blame] | 88 |    * Debug handler | 
 | 89 |    * | 
 | 90 |    * @var mixed | 
 | 91 |    */ | 
| robert | b0fac3e | 2007-01-15 23:53:25 +0000 | [diff] [blame] | 92 |   protected $debugHandler_ = null; | 
| Mark Slee | ad58f95 | 2007-01-03 19:23:50 +0000 | [diff] [blame] | 93 |  | 
 | 94 |   /** | 
| Mark Slee | 6e53644 | 2006-06-30 18:28:50 +0000 | [diff] [blame] | 95 |    * Socket constructor | 
 | 96 |    * | 
| Mark Slee | ad58f95 | 2007-01-03 19:23:50 +0000 | [diff] [blame] | 97 |    * @param string $host         Remote hostname | 
 | 98 |    * @param int    $port         Remote port | 
 | 99 |    * @param bool   $persist      Whether to use a persistent socket | 
 | 100 |    * @param string $debugHandler Function to call for error logging | 
| Mark Slee | 6e53644 | 2006-06-30 18:28:50 +0000 | [diff] [blame] | 101 |    */ | 
| Mark Slee | ad58f95 | 2007-01-03 19:23:50 +0000 | [diff] [blame] | 102 |   public function __construct($host='localhost', | 
 | 103 |                               $port=9090, | 
 | 104 |                               $persist=FALSE, | 
 | 105 |                               $debugHandler=null) { | 
| Mark Slee | 6e53644 | 2006-06-30 18:28:50 +0000 | [diff] [blame] | 106 |     $this->host_ = $host; | 
 | 107 |     $this->port_ = $port; | 
 | 108 |     $this->persist_ = $persist; | 
| Mark Slee | ad58f95 | 2007-01-03 19:23:50 +0000 | [diff] [blame] | 109 |     $this->debugHandler_ = $debugHandler ? $debugHandler : 'error_log'; | 
| Mark Slee | 6e53644 | 2006-06-30 18:28:50 +0000 | [diff] [blame] | 110 |   } | 
 | 111 |  | 
 | 112 |   /** | 
| Bryan Duxbury | 17115d7 | 2010-08-12 16:59:19 +0000 | [diff] [blame] | 113 |    * @param resource $handle | 
 | 114 |    * @return void | 
 | 115 |    */ | 
 | 116 |   public function setHandle($handle) { | 
 | 117 |     $this->handle_ = $handle; | 
 | 118 |   } | 
 | 119 |  | 
 | 120 |   /** | 
| Mark Slee | ade2c83 | 2006-09-08 03:41:50 +0000 | [diff] [blame] | 121 |    * Sets the send timeout. | 
 | 122 |    * | 
| David Reiss | 5ab303c | 2009-03-26 04:27:47 +0000 | [diff] [blame] | 123 |    * @param int $timeout  Timeout in milliseconds. | 
| Mark Slee | ade2c83 | 2006-09-08 03:41:50 +0000 | [diff] [blame] | 124 |    */ | 
 | 125 |   public function setSendTimeout($timeout) { | 
 | 126 |     $this->sendTimeout_ = $timeout; | 
 | 127 |   } | 
 | 128 |  | 
 | 129 |   /** | 
 | 130 |    * Sets the receive timeout. | 
 | 131 |    * | 
| David Reiss | 5ab303c | 2009-03-26 04:27:47 +0000 | [diff] [blame] | 132 |    * @param int $timeout  Timeout in milliseconds. | 
| Mark Slee | ade2c83 | 2006-09-08 03:41:50 +0000 | [diff] [blame] | 133 |    */ | 
 | 134 |   public function setRecvTimeout($timeout) { | 
 | 135 |     $this->recvTimeout_ = $timeout; | 
 | 136 |   } | 
 | 137 |  | 
 | 138 |   /** | 
 | 139 |    * Sets debugging output on or off | 
 | 140 |    * | 
 | 141 |    * @param bool $debug | 
 | 142 |    */ | 
 | 143 |   public function setDebug($debug) { | 
 | 144 |     $this->debug_ = $debug; | 
 | 145 |   } | 
 | 146 |  | 
 | 147 |   /** | 
| Mark Slee | 0cdc6c8 | 2007-11-13 10:19:08 +0000 | [diff] [blame] | 148 |    * Get the host that this socket is connected to | 
 | 149 |    * | 
 | 150 |    * @return string host | 
 | 151 |    */ | 
 | 152 |   public function getHost() { | 
 | 153 |     return $this->host_; | 
 | 154 |   } | 
 | 155 |  | 
 | 156 |   /** | 
 | 157 |    * Get the remote port that this socket is connected to | 
 | 158 |    * | 
 | 159 |    * @return int port | 
 | 160 |    */ | 
 | 161 |   public function getPort() { | 
 | 162 |     return $this->port_; | 
 | 163 |   } | 
 | 164 |  | 
 | 165 |   /** | 
| Mark Slee | 6e53644 | 2006-06-30 18:28:50 +0000 | [diff] [blame] | 166 |    * Tests whether this is open | 
 | 167 |    * | 
 | 168 |    * @return bool true if the socket is open | 
 | 169 |    */ | 
 | 170 |   public function isOpen() { | 
 | 171 |     return is_resource($this->handle_); | 
 | 172 |   } | 
 | 173 |  | 
 | 174 |   /** | 
 | 175 |    * Connects the socket. | 
 | 176 |    */ | 
 | 177 |   public function open() { | 
| Bryan Duxbury | 17115d7 | 2010-08-12 16:59:19 +0000 | [diff] [blame] | 178 |     if ($this->isOpen()) { | 
 | 179 |       throw new TTransportException('Socket already connected', TTransportException::ALREADY_OPEN); | 
 | 180 |     } | 
 | 181 |  | 
 | 182 |     if (empty($this->host_)) { | 
 | 183 |       throw new TTransportException('Cannot open null host', TTransportException::NOT_OPEN); | 
 | 184 |     } | 
 | 185 |  | 
 | 186 |     if ($this->port_ <= 0) { | 
 | 187 |       throw new TTransportException('Cannot open without port', TTransportException::NOT_OPEN); | 
 | 188 |     } | 
| Mark Slee | 0cdc6c8 | 2007-11-13 10:19:08 +0000 | [diff] [blame] | 189 |  | 
| Mark Slee | 6e53644 | 2006-06-30 18:28:50 +0000 | [diff] [blame] | 190 |     if ($this->persist_) { | 
| Mark Slee | d7cc1c4 | 2006-10-04 16:49:07 +0000 | [diff] [blame] | 191 |       $this->handle_ = @pfsockopen($this->host_, | 
 | 192 |                                    $this->port_, | 
 | 193 |                                    $errno, | 
 | 194 |                                    $errstr, | 
 | 195 |                                    $this->sendTimeout_/1000.0); | 
 | 196 |     } else { | 
 | 197 |       $this->handle_ = @fsockopen($this->host_, | 
| Mark Slee | ade2c83 | 2006-09-08 03:41:50 +0000 | [diff] [blame] | 198 |                                   $this->port_, | 
 | 199 |                                   $errno, | 
 | 200 |                                   $errstr, | 
 | 201 |                                   $this->sendTimeout_/1000.0); | 
| Mark Slee | 6e53644 | 2006-06-30 18:28:50 +0000 | [diff] [blame] | 202 |     } | 
| Mark Slee | ade2c83 | 2006-09-08 03:41:50 +0000 | [diff] [blame] | 203 |  | 
 | 204 |     // Connect failed? | 
 | 205 |     if ($this->handle_ === FALSE) { | 
| Martin Kraemer | 0b64e77 | 2007-02-07 22:39:58 +0000 | [diff] [blame] | 206 |       $error = 'TSocket: Could not connect to '.$this->host_.':'.$this->port_.' ('.$errstr.' ['.$errno.'])'; | 
| Mark Slee | ade2c83 | 2006-09-08 03:41:50 +0000 | [diff] [blame] | 207 |       if ($this->debug_) { | 
| Mark Slee | e7714a6 | 2007-01-11 01:26:00 +0000 | [diff] [blame] | 208 |         call_user_func($this->debugHandler_, $error); | 
| Mark Slee | ade2c83 | 2006-09-08 03:41:50 +0000 | [diff] [blame] | 209 |       } | 
| Mark Slee | 7679196 | 2007-03-14 02:47:35 +0000 | [diff] [blame] | 210 |       throw new TException($error); | 
| Mark Slee | 6e53644 | 2006-06-30 18:28:50 +0000 | [diff] [blame] | 211 |     } | 
| Mark Slee | 0cdc6c8 | 2007-11-13 10:19:08 +0000 | [diff] [blame] | 212 |  | 
| Mark Slee | ade2c83 | 2006-09-08 03:41:50 +0000 | [diff] [blame] | 213 |     stream_set_timeout($this->handle_, 0, $this->sendTimeout_*1000); | 
 | 214 |     $this->sendTimeoutSet_ = TRUE; | 
| Mark Slee | 6e53644 | 2006-06-30 18:28:50 +0000 | [diff] [blame] | 215 |   } | 
 | 216 |  | 
 | 217 |   /** | 
| Mark Slee | ade2c83 | 2006-09-08 03:41:50 +0000 | [diff] [blame] | 218 |    * Closes the socket. | 
| Mark Slee | 6e53644 | 2006-06-30 18:28:50 +0000 | [diff] [blame] | 219 |    */ | 
 | 220 |   public function close() { | 
 | 221 |     if (!$this->persist_) { | 
| Mark Slee | ade2c83 | 2006-09-08 03:41:50 +0000 | [diff] [blame] | 222 |       @fclose($this->handle_); | 
 | 223 |       $this->handle_ = null; | 
| Mark Slee | 6e53644 | 2006-06-30 18:28:50 +0000 | [diff] [blame] | 224 |     } | 
 | 225 |   } | 
| Mark Slee | 0cdc6c8 | 2007-11-13 10:19:08 +0000 | [diff] [blame] | 226 |  | 
| Mark Slee | 6e53644 | 2006-06-30 18:28:50 +0000 | [diff] [blame] | 227 |   /** | 
 | 228 |    * Uses stream get contents to do the reading | 
| Mark Slee | ade2c83 | 2006-09-08 03:41:50 +0000 | [diff] [blame] | 229 |    * | 
 | 230 |    * @param int $len How many bytes | 
 | 231 |    * @return string Binary data | 
| Mark Slee | 6e53644 | 2006-06-30 18:28:50 +0000 | [diff] [blame] | 232 |    */ | 
 | 233 |   public function readAll($len) { | 
| Mark Slee | ade2c83 | 2006-09-08 03:41:50 +0000 | [diff] [blame] | 234 |     if ($this->sendTimeoutSet_) { | 
 | 235 |       stream_set_timeout($this->handle_, 0, $this->recvTimeout_*1000); | 
 | 236 |       $this->sendTimeoutSet_ = FALSE; | 
 | 237 |     } | 
| Mark Slee | 794993d | 2006-09-20 01:56:10 +0000 | [diff] [blame] | 238 |     // This call does not obey stream_set_timeout values! | 
 | 239 |     // $buf = @stream_get_contents($this->handle_, $len); | 
 | 240 |  | 
 | 241 |     $pre = null; | 
| Mark Slee | 29f5f67 | 2006-09-28 03:19:03 +0000 | [diff] [blame] | 242 |     while (TRUE) { | 
| Mark Slee | 794993d | 2006-09-20 01:56:10 +0000 | [diff] [blame] | 243 |       $buf = @fread($this->handle_, $len); | 
| Bryan Duxbury | cecbe0f | 2010-11-19 00:06:51 +0000 | [diff] [blame] | 244 |       if ($buf === FALSE) { | 
| Martin Kraemer | 0b64e77 | 2007-02-07 22:39:58 +0000 | [diff] [blame] | 245 |         $md = stream_get_meta_data($this->handle_); | 
| Bryan Duxbury | cecbe0f | 2010-11-19 00:06:51 +0000 | [diff] [blame] | 246 |         if (true === $md['timed_out'] && false === $md['blocked']) { | 
| Bryan Duxbury | 17115d7 | 2010-08-12 16:59:19 +0000 | [diff] [blame] | 247 |           throw new TTransportException('TSocket: timed out reading '.$len.' bytes from '. | 
| Mark Slee | 7679196 | 2007-03-14 02:47:35 +0000 | [diff] [blame] | 248 |                                $this->host_.':'.$this->port_); | 
| Martin Kraemer | 0b64e77 | 2007-02-07 22:39:58 +0000 | [diff] [blame] | 249 |         } else { | 
| Bryan Duxbury | 17115d7 | 2010-08-12 16:59:19 +0000 | [diff] [blame] | 250 |           throw new TTransportException('TSocket: Could not read '.$len.' bytes from '. | 
| Mark Slee | 7679196 | 2007-03-14 02:47:35 +0000 | [diff] [blame] | 251 |                                $this->host_.':'.$this->port_); | 
| Martin Kraemer | 0b64e77 | 2007-02-07 22:39:58 +0000 | [diff] [blame] | 252 |         } | 
| Bryan Duxbury | 7d1517a | 2011-02-22 18:17:23 +0000 | [diff] [blame] | 253 |       } | 
 | 254 |       else if (($sz = strlen($buf)) < $len) { | 
 | 255 |         if((strlen($buf) == 0) && feof($this->handle_)){ | 
 | 256 |           throw new TTransportException('TSocket read 0 bytes'); | 
 | 257 |         }; | 
 | 258 |  | 
| Mark Slee | 794993d | 2006-09-20 01:56:10 +0000 | [diff] [blame] | 259 |         $md = stream_get_meta_data($this->handle_); | 
| Bryan Duxbury | cecbe0f | 2010-11-19 00:06:51 +0000 | [diff] [blame] | 260 |         if (true === $md['timed_out'] && false === $md['blocked']) { | 
| Bryan Duxbury | 17115d7 | 2010-08-12 16:59:19 +0000 | [diff] [blame] | 261 |           throw new TTransportException('TSocket: timed out reading '.$len.' bytes from '. | 
| Mark Slee | 7679196 | 2007-03-14 02:47:35 +0000 | [diff] [blame] | 262 |                                $this->host_.':'.$this->port_); | 
| Mark Slee | 794993d | 2006-09-20 01:56:10 +0000 | [diff] [blame] | 263 |         } else { | 
 | 264 |           $pre .= $buf; | 
 | 265 |           $len -= $sz; | 
 | 266 |         } | 
 | 267 |       } else { | 
 | 268 |         return $pre.$buf; | 
 | 269 |       } | 
| Mark Slee | ade2c83 | 2006-09-08 03:41:50 +0000 | [diff] [blame] | 270 |     } | 
| Mark Slee | 6e53644 | 2006-06-30 18:28:50 +0000 | [diff] [blame] | 271 |   } | 
 | 272 |  | 
 | 273 |   /** | 
 | 274 |    * Read from the socket | 
| Mark Slee | ade2c83 | 2006-09-08 03:41:50 +0000 | [diff] [blame] | 275 |    * | 
 | 276 |    * @param int $len How many bytes | 
 | 277 |    * @return string Binary data | 
| Mark Slee | 6e53644 | 2006-06-30 18:28:50 +0000 | [diff] [blame] | 278 |    */ | 
 | 279 |   public function read($len) { | 
| Mark Slee | ade2c83 | 2006-09-08 03:41:50 +0000 | [diff] [blame] | 280 |     if ($this->sendTimeoutSet_) { | 
 | 281 |       stream_set_timeout($this->handle_, 0, $this->recvTimeout_*1000); | 
 | 282 |       $this->sendTimeoutSet_ = FALSE; | 
 | 283 |     } | 
| Mark Slee | 794993d | 2006-09-20 01:56:10 +0000 | [diff] [blame] | 284 |     $data = @fread($this->handle_, $len); | 
| Bryan Duxbury | cecbe0f | 2010-11-19 00:06:51 +0000 | [diff] [blame] | 285 |     if ($data === FALSE) { | 
| Martin Kraemer | 0b64e77 | 2007-02-07 22:39:58 +0000 | [diff] [blame] | 286 |       $md = stream_get_meta_data($this->handle_); | 
| Bryan Duxbury | cecbe0f | 2010-11-19 00:06:51 +0000 | [diff] [blame] | 287 |       if (true === $md['timed_out'] && false === $md['blocked']) { | 
| Bryan Duxbury | 17115d7 | 2010-08-12 16:59:19 +0000 | [diff] [blame] | 288 |         throw new TTransportException('TSocket: timed out reading '.$len.' bytes from '. | 
| Mark Slee | 7679196 | 2007-03-14 02:47:35 +0000 | [diff] [blame] | 289 |                              $this->host_.':'.$this->port_); | 
| Martin Kraemer | 0b64e77 | 2007-02-07 22:39:58 +0000 | [diff] [blame] | 290 |       } else { | 
| Bryan Duxbury | 17115d7 | 2010-08-12 16:59:19 +0000 | [diff] [blame] | 291 |         throw new TTransportException('TSocket: Could not read '.$len.' bytes from '. | 
| Mark Slee | 7679196 | 2007-03-14 02:47:35 +0000 | [diff] [blame] | 292 |                              $this->host_.':'.$this->port_); | 
| Martin Kraemer | 0b64e77 | 2007-02-07 22:39:58 +0000 | [diff] [blame] | 293 |       } | 
| Mark Slee | 6e53644 | 2006-06-30 18:28:50 +0000 | [diff] [blame] | 294 |     } | 
| Bryan Duxbury | 7d1517a | 2011-02-22 18:17:23 +0000 | [diff] [blame] | 295 |     elseif((strlen($data) == 0) && feof($this->handle_)) | 
 | 296 |     { | 
 | 297 |       throw new TTransportException('TSocket read 0 bytes'); | 
 | 298 |     }; | 
| Mark Slee | 6e53644 | 2006-06-30 18:28:50 +0000 | [diff] [blame] | 299 |     return $data; | 
 | 300 |   } | 
 | 301 |  | 
 | 302 |   /** | 
 | 303 |    * Write to the socket. | 
| Mark Slee | ade2c83 | 2006-09-08 03:41:50 +0000 | [diff] [blame] | 304 |    * | 
 | 305 |    * @param string $buf The data to write | 
| Mark Slee | 6e53644 | 2006-06-30 18:28:50 +0000 | [diff] [blame] | 306 |    */ | 
 | 307 |   public function write($buf) { | 
| Mark Slee | ade2c83 | 2006-09-08 03:41:50 +0000 | [diff] [blame] | 308 |     if (!$this->sendTimeoutSet_) { | 
 | 309 |       stream_set_timeout($this->handle_, 0, $this->sendTimeout_*1000); | 
 | 310 |       $this->sendTimeoutSet_ = TRUE; | 
 | 311 |     } | 
| Mark Slee | d395d57 | 2007-02-27 01:16:55 +0000 | [diff] [blame] | 312 |     while (strlen($buf) > 0) { | 
| Mark Slee | ade2c83 | 2006-09-08 03:41:50 +0000 | [diff] [blame] | 313 |       $got = @fwrite($this->handle_, $buf); | 
 | 314 |       if ($got === 0 || $got === FALSE) { | 
| Martin Kraemer | 0b64e77 | 2007-02-07 22:39:58 +0000 | [diff] [blame] | 315 |         $md = stream_get_meta_data($this->handle_); | 
 | 316 |         if ($md['timed_out']) { | 
| Bryan Duxbury | 17115d7 | 2010-08-12 16:59:19 +0000 | [diff] [blame] | 317 |           throw new TTransportException('TSocket: timed out writing '.strlen($buf).' bytes from '. | 
| Mark Slee | 7679196 | 2007-03-14 02:47:35 +0000 | [diff] [blame] | 318 |                                $this->host_.':'.$this->port_); | 
| Martin Kraemer | 0b64e77 | 2007-02-07 22:39:58 +0000 | [diff] [blame] | 319 |         } else { | 
| Bryan Duxbury | 17115d7 | 2010-08-12 16:59:19 +0000 | [diff] [blame] | 320 |             throw new TTransportException('TSocket: Could not write '.strlen($buf).' bytes '. | 
| Mark Slee | 7679196 | 2007-03-14 02:47:35 +0000 | [diff] [blame] | 321 |                                  $this->host_.':'.$this->port_); | 
| Martin Kraemer | 0b64e77 | 2007-02-07 22:39:58 +0000 | [diff] [blame] | 322 |         } | 
| Mark Slee | 6e53644 | 2006-06-30 18:28:50 +0000 | [diff] [blame] | 323 |       } | 
 | 324 |       $buf = substr($buf, $got); | 
 | 325 |     } | 
 | 326 |   } | 
 | 327 |  | 
 | 328 |   /** | 
 | 329 |    * Flush output to the socket. | 
 | 330 |    */ | 
 | 331 |   public function flush() { | 
| Mark Slee | ade2c83 | 2006-09-08 03:41:50 +0000 | [diff] [blame] | 332 |     $ret = fflush($this->handle_); | 
 | 333 |     if ($ret === FALSE) { | 
| Mark Slee | 7679196 | 2007-03-14 02:47:35 +0000 | [diff] [blame] | 334 |       throw new TException('TSocket: Could not flush: '. | 
 | 335 |                            $this->host_.':'.$this->port_); | 
| Mark Slee | ade2c83 | 2006-09-08 03:41:50 +0000 | [diff] [blame] | 336 |     } | 
| Mark Slee | 6e53644 | 2006-06-30 18:28:50 +0000 | [diff] [blame] | 337 |   } | 
 | 338 | } |