示例#1
0
文件: Client.php 项目: bt51/ntp
 /**
  * Sends a request to the remote ntp server for the current time.
  * The current time returned is UTC.
  *
  * @return \DateTime
  */
 public function getTime()
 {
     $packet = $this->buildPacket();
     $this->write($packet);
     $time = $this->unpack($this->read());
     $time -= 2208988800;
     $this->socket->close();
     return \DateTime::createFromFormat('U', $time, new \DateTimeZone('UTC'));
 }
示例#2
0
文件: Client.php 项目: vend/statsd
 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();
 }
示例#4
0
 /**
  * @expectedException Phanglia\ConnectionException
  */
 public function testConnectionProblem()
 {
     $socket = new Socket('-_/#$*&!)@&#$', 32132, []);
     $socket->send('some_payload');
     $this->assertTrue($socket->isOpen());
     $socket->close();
     $this->assertFalse($socket->isOpen());
 }
示例#5
0
文件: Server.php 项目: navarr/sockets
 /**
  * Disconnect all the Clients and shut down the server.
  *
  * @return void
  */
 private function shutDownEverything()
 {
     foreach ($this->clients as $client) {
         $this->disconnect($client);
     }
     $this->masterSocket->close();
     unset($this->hooks, $this->address, $this->port, $this->timeout, $this->domain, $this->masterSocket, $this->maxClients, $this->maxRead, $this->clients, $this->readType);
 }
 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();
 }
示例#7
0
 /**
  * This method will call the onClose method which will call this method in all
  * observing objects. After that, the TCP connection will be closed.
  * Use the disconnect() method if you want to close the WebSocket Connection cleanly
  *
  * @param int $nReason The status code or reason for the close
  * @param string $sReason The status code or reason for the close as text
  * @return boolean True on succes, false otherwise
  */
 public function close($nReason = null, $sReason = null)
 {
     /* Update the readystate */
     $this->m_nReadyState = static::STATE_CLOSED;
     /* Raise events */
     $this->onClose($nReason, $sReason);
     /* This connection is not in CONNECTING state anymore */
     unset(static::$aInConnectingState[$this->m_sIp]);
     /* Call the parent close function to close the TCP connection */
     return parent::close();
 }
示例#8
0
 /**
  * Close the socket
  * 
  * @return void
  */
 public function close()
 {
     if (null !== $this->socket) {
         $this->socket->close();
     }
 }
 public function close()
 {
     $this->socket->close();
 }
示例#10
0
 public function finish()
 {
     $this->socket->close();
     return $this->totalCounts->wrong + $this->totalCounts->exceptions;
 }