/** * Write the Request Header * <req_len> + <req_type> + <topic_len> + <topic> + <partition> * * @param Socket $socket Socket * * @return void */ protected function writeRequestHeader(Socket $socket) { // REQUEST_LENGTH (int) + REQUEST_TYPE (short) $socket->write(pack('N', $this->sizeInBytes() + 2)); $socket->write(pack('n', $this->id)); // TOPIC_SIZE (short) + TOPIC (bytes) $socket->write(pack('n', strlen($this->topic)) . $this->topic); // PARTITION (int) $socket->write(pack('N', $this->partition)); }
public function flush() { $this->socket->open(); $metrics = array_map(function (MetricInterface $metric) { return $metric->getData(); }, $this->queue); $packets = $this->fillPackets($metrics); foreach ($packets as $packet) { $this->socket->write($packet); } $this->queue = []; $this->socket->close(); }
public static function shutdownApplicationServer() { self::$clientClassesLoader && ClassLoader::removeLoader(self::$clientClassesLoader); // Send shutdown message (this is not supported by live servers // but functionality added via EascMessageFactory::setHandler()) try { $s = new Socket(self::$bindAddress[0], self::$bindAddress[1]); $s->connect(); $s->write(pack('Nc4Na*', DEFAULT_PROTOCOL_MAGIC_NUMBER, 1, 0, 61, FALSE, 0, NULL)); $s->close(); } catch (Throwable $e) { // Fall through, below should terminate the process anyway } $status = self::$serverProcess->out->readLine(); if (!strlen($status) || '+' != $status[0]) { while ($l = self::$serverProcess->out->readLine()) { $status .= $l; } while ($l = self::$serverProcess->err->readLine()) { $status .= $l; } self::$serverProcess->close(); throw new IllegalStateException($status); } self::$serverProcess->close(); }
/** * Forces the server to refresh its configuration. * * @since 5.1 * @return string Server result string. */ public function refresh() { try { $result = ''; $auth = ModuleServerAuthenticator::instance('ModuleServerAuthenticator'); $this->socket->connect($this->host, $this->port); $request = 'REFRESH Module/1.0' . "\r\n"; $request .= 'User: admin' . "\r\n"; $request .= 'Password: '******'admin') . "\r\n"; $this->socket->write($request); $result = $this->socket->readAll(); $this->socket->disconnect(); } catch (\Innomatic\Net\Socket\SocketException $e) { $result = 'Module server is down.' . "\n"; } return $result; }
/** * force the ModuleServiceSocketHandler to refresh the registry * * @since 5.1 */ protected function force_refresh() { print "force_refresh" . "\n"; $request = ''; $address = '127.0.0.1'; $context = \Innomatic\Module\Server\ModuleServerContext::instance('\\Innomatic\\Module\\Server\\ModuleServerContext'); try { $port = $context->getConfig()->getKey('service_port'); $this->socket->connect($address, $port); $request = 'REFRESH Module/1.1' . "\r\n"; $request .= 'User: admin' . "\r\n"; $request .= 'Password: '******'admin') . "\r\n"; $this->socket->write($request); $result = $this->socket->readAll(); $this->socket->disconnect(); } catch (\Innomatic\Net\Socket\SocketException $e) { print "Cannot refresh: server " . $address . ":" . $port . " down!" . "\n"; } print $result; }
public static function shutdownServer() { // Tell the server to shut down try { $c = new Socket(self::$bindAddress[0], self::$bindAddress[1]); $c->connect(); $c->write("HALT\n"); $c->close(); } catch (Throwable $ignored) { // Fall through, below should terminate the process anyway } $status = self::$serverProcess->out->readLine(); if (!strlen($status) || '+' != $status[0]) { while ($l = self::$serverProcess->out->readLine()) { $status .= $l; } while ($l = self::$serverProcess->err->readLine()) { $status .= $l; } self::$serverProcess->close(); throw new IllegalStateException($status); } self::$serverProcess->close(); }
/** * Use this method to write to the client. * * @param string $sMessage The data that has to be send to the client * @return boolean True on succes, false otherwise */ public function write($sMessage) { if ($this->m_bConnected) { return parent::write($sMessage); } return false; }
/** * Send messages to Kafka * * @param array $messages Messages to send * @param string $topic Topic * @param integer $partition Partition * * @return boolean */ public function send(array $messages, $topic, $partition = 0xffffffff) { $this->connect(); return $this->socket->write(Encoder::encode_produce_request($topic, $partition, $messages, $this->compression)); }
/** * sends a 10 bytes value * * @param integer $value */ private function putInteger($value) { $intValue = sprintf("%0" . self::FITNESSE_INTEGER . "d", $value); $this->socket->write($intValue, strlen($intValue)); }
public function testWrite_writePartial_continuesCorrectly() { $data = ['part 1', 'and part 2', 'part 3']; $this->_socketCreateSuccess(); $this->_socketConnectSuccess(); $this->_getNativeFunctionMock()->expects($this->exactly(3))->method('socket_write')->withConsecutive([$this->anything(), join('', array_slice($data, 0)), strlen(join('', array_slice($data, 0)))], [$this->anything(), join('', array_slice($data, 1)), strlen(join('', array_slice($data, 1)))], [$this->anything(), join('', array_slice($data, 2)), strlen(join('', array_slice($data, 2)))])->willReturnOnConsecutiveCalls(strlen($data[0]), strlen($data[1]), strlen($data[2])); $socket = new Socket(); $socket->connect(); $written = $socket->write(join('', $data)); $this->assertEquals(strlen(join('', $data)), $written); }
public function writeTo(Socket $socket, $data) { if (!$socket instanceof self) { $data = $this->encode($data); } return $socket->write($data); }
/** * Write a request packet to the remote ntp server * * @param string $packet The packet to send * * @return void */ protected function write($packet) { $this->socket->write($packet); }