private static function _setInstance() { /** * Cannot use str* functions for byte counting because multibyte * characters will be read a single bytes. * * See: http://us.php.net/manual/en/mbstring.overload.php */ if (ini_get('mbstring.func_overload') & 2) { self::$_instance = new TStringFunc_Mbstring(); } else { self::$_instance = new TStringFunc_Core(); } }
public function writeString($value) { $len = TStringFuncFactory::create()->strlen($value); $result = $this->writeI32($len); if ($len) { $this->trans_->write($value, $len); } return $result + $len; }
/** * Write to the socket. * * @param string $buf The data to write */ public function write($buf) { $null = null; $write = array($this->handle_); // keep writing until all the data has been written while (TStringFuncFactory::create()->strlen($buf) > 0) { // wait for stream to become available for writing $writable = @stream_select($null, $write, $null, $this->sendTimeoutSec_, $this->sendTimeoutUsec_); if ($writable > 0) { // write buffer to stream $written = @stream_socket_sendto($this->handle_, $buf); if ($written === -1 || $written === false) { throw new TTransportException('TSocket: Could not write ' . TStringFuncFactory::create()->strlen($buf) . ' bytes ' . $this->host_ . ':' . $this->port_); } // determine how much of the buffer is left to write $buf = TStringFuncFactory::create()->substr($buf, $written); } else { if ($writable === 0) { throw new TTransportException('TSocket: timed out writing ' . TStringFuncFactory::create()->strlen($buf) . ' bytes from ' . $this->host_ . ':' . $this->port_); } else { throw new TTransportException('TSocket: Could not write ' . TStringFuncFactory::create()->strlen($buf) . ' bytes ' . $this->host_ . ':' . $this->port_); } } } }