/** * Callback for when server should be shut down */ public static function shutdown() { $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(); }
/** * Callback for when server should be shut down * * @return vid */ public static function shutdown() { $c = new Socket(self::$bindAddress[0], self::$bindAddress[1]); $c->connect(); $c->write("HALT\n"); $c->close(); }
/** * Constructor * * @param rdbms.DSN dsn */ public function __construct($dsn) { parent::__construct($dsn); $this->formatter = new StatementFormatter($this, $this->getDialect()); $sock = new Socket($this->dsn->getHost(), $this->dsn->getPort(1433)); $sock->setTimeout(-1); $this->handle = $this->getProtocol($sock); }
/** * Constructor * * @param rdbms.DSN dsn */ public function __construct($dsn) { parent::__construct($dsn); $this->formatter = new StatementFormatter($this, new MysqlDialect()); // Use local socket (unix socket on Un*x systems, named pipe on Windows) // if "." is supplied as hostname $host = $this->dsn->getHost(); if ('.' === $host) { $sock = LocalSocket::forName(PHP_OS)->newInstance($this->dsn->getProperty('socket', null)); } else { $sock = new Socket($host, $this->dsn->getPort(3306)); $sock->setTimeout(-1); } $this->handle = new MySqlxProtocol($sock); }
/** * Connect, then enable crypto * * @param float $timeout * @return bool * @throws peer.SSLUnverifiedPeerException if peer verification fails * @throws peer.SSLHandshakeException if handshake fails for any other reasons * @throws peer.ConnectException for all other reasons */ public function connect($timeout = 2.0) { if ($this->isConnected()) { return true; } parent::connect($timeout); if (stream_socket_enable_crypto($this->_sock, true, $this->cryptoImpl)) { return true; } // Parse OpenSSL errors: if (preg_match('/error:(\\d+):(.+)/', key(end(\xp::$errors[__FILE__])), $matches)) { switch ($matches[1]) { case '14090086': $e = new SSLUnverifiedPeerException($matches[2]); break; default: $e = new SSLHandshakeException($matches[2]); break; } } else { $e = new SSLHandshakeException('Unable to enable crypto.'); } $this->close(); throw $e; }
/** * Connect to a socket. If socket still open from last request (which * is the case when unread data is left on it by not reading the body, * e.g.), use the quick & dirty way: Close and reopen! * * @param peer.Socket $s * @param double $read Read timeout * @param double $connect Connect timeout * @return peer.Socket */ protected function connect($s, $read, $connect) { $s->isConnected() && $s->close(); $s->setTimeout($read); $s->connect($connect); return $s; }
/** * Send a HTTP header message * * @param peer.Socket socket * @param int sc the status code * @param string message status message * @param string[] headers */ protected function sendHeader(Socket $socket, $sc, $message, array $headers) { $socket->write('HTTP/1.1 ' . $sc . ' ' . $message . "\r\n"); $socket->write('Date: ' . gmdate('D, d M Y H:i:s T') . "\r\n"); $socket->write("Server: XP/PHP\r\n"); $socket->write("Connection: close\r\n"); foreach ($headers as $header) { $socket->write($header . "\r\n"); } $socket->write("\r\n"); }
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 (\lang\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 \lang\IllegalStateException($status); } self::$serverProcess->close(); }
/** * Send a HTTP header message * * @param peer.Socket socket * @param int sc the status code * @param string message status message * @param [:var] headers * @return int */ protected function sendHeader(Socket $socket, $sc, $message, array $headers) { $socket->write('HTTP/1.1 ' . $sc . ' ' . $message . "\r\n"); $socket->write('Date: ' . gmdate('D, d M Y H:i:s T') . "\r\n"); $socket->write('Server: XP/PHP ' . phpversion() . "\r\n"); $socket->write("Connection: close\r\n"); foreach ($headers as $key => $value) { if (is_array($value)) { foreach ($value as $val) { $socket->write($key . ': ' . $val . "\r\n"); } } else { $socket->write($key . ': ' . $value . "\r\n"); } } $socket->write("\r\n"); return $sc; }
/** * Retrieve transfer socket * * @return peer.Socket */ public function transferSocket() { $port = $this->expect($this->sendCommand('PASV'), [227]); $a = $p = []; sscanf($port, '%*[^(] (%d,%d,%d,%d,%d,%d)', $a[0], $a[1], $a[2], $a[3], $p[0], $p[1]); // Open transfer socket $transfer = new Socket(implode('.', $a), $p[0] * 256 + $p[1]); $transfer->connect(); return $transfer; }