}
public function putBack($data) {
- if (empty($this->rBuf_)) {
+ if (strlen($this->rBuf_) === 0) {
$this->rBuf_ = $data;
- }
- else {
+ } else {
$this->rBuf_ = ($data . $this->rBuf_);
}
}
-
+
public function read($len) {
- if (empty($this->rBuf_)){
+ if (strlen($this->rBuf_) === 0) {
$this->rBuf_ = $this->transport_->read($this->rBufSize_);
}
}
public function flush() {
- if (!empty($this->wBuf_)) {
+ if (strlen($this->wBuf_) > 0) {
$this->transport_->write($this->wBuf_);
$this->wBuf_ = '';
}
return $this->transport_->read($len);
}
- if (empty($this->rBuf_)) {
+ if (strlen($this->rBuf_) === 0) {
$this->readFrame();
}
$this->rBuf_ = null;
return $out;
}
-
+
// Return substr
$out = substr($this->rBuf_, 0, $len);
$this->rBuf_ = substr($this->rBuf_, $len);
* @param string $data data to return
*/
public function putBack($data) {
- if (empty($this->rBuf_)) {
+ if (strlen($this->rBuf_) === 0) {
$this->rBuf_ = $data;
- }
- else {
+ } else {
$this->rBuf_ = ($data . $this->rBuf_);
}
}
'User-Agent: PHP/THttpClient',
'Content-Type: application/x-thrift',
'Content-Length: '.strlen($this->buf_));
-
+
$options = array('method' => 'POST',
'header' => implode("\r\n", $headers),
'max_redirects' => 1,
}
public function read($len) {
- if (empty($this->buf_)) {
+ if (strlen($this->buf_) === 0) {
throw new TTransportException('TMemoryBuffer: Could not read ' .
$len . ' bytes from buffer.',
TTransportException::UNKNOWN);
}
}
}
-
+
public function close() {
if ($this->read_) {
@fclose($this->inStream_);
/**
* Remote hostname
- *
+ *
* @var string
*/
protected $host_ = 'localhost';
$this->debug_ = $debug;
}
+ /**
+ * Get the host that this socket is connected to
+ *
+ * @return string host
+ */
+ public function getHost() {
+ return $this->host_;
+ }
+
+ /**
+ * Get the remote port that this socket is connected to
+ *
+ * @return int port
+ */
+ public function getPort() {
+ return $this->port_;
+ }
+
/**
* Tests whether this is open
*
* Connects the socket.
*/
public function open() {
+
if ($this->persist_) {
$this->handle_ = @pfsockopen($this->host_,
$this->port_,
}
throw new TException($error);
}
-
+
stream_set_timeout($this->handle_, 0, $this->sendTimeout_*1000);
$this->sendTimeoutSet_ = TRUE;
}
$this->handle_ = null;
}
}
-
+
/**
* Uses stream get contents to do the reading
*
}
}
+ /**
+ * Add a server to the pool
+ *
+ * This function does not prevent you from adding a duplicate server entry.
+ *
+ * @param string $host hostname or IP
+ * @param int $port port
+ */
+ public function addServer($host, $port) {
+ $this->servers_[] = array('host' => $host, 'port' => $port);
+ }
+
/**
* Sets how many time to keep retrying a host in the connect function.
*
// Set underlying TSocket params to this one
$this->host_ = $host;
$this->port_ = $port;
-
+
// Try up to numRetries_ connections per server
for ($attempt = 0; $attempt < $this->numRetries_; $attempt++) {
try {