protected function sendRequest(Request $request) { $xml = $request->getXml(); @stream_set_timeout($this->socket, 20); // timeout 20 s (to write the request) // send request $this->reqhandle++; if ($this->protocol == 1) { $bytes = pack('Va*', strlen($xml), $xml); } else { $bytes = pack('VVa*', strlen($xml), $this->reqhandle, $xml); } $bytes_to_write = strlen($bytes); // increase sent counter ... self::$sent += $bytes_to_write; while ($bytes_to_write > 0) { $r = fwrite($this->socket, $bytes); if ($r === false || $r == 0) { throw new Exception('Connection interupted'); } $bytes_to_write -= $r; if ($bytes_to_write == 0) { break; } $bytes = substr($bytes, $r); } }