HttpServer

An HTTP and WebSockets server.

You receive HTTP requests by providing a @see \io\vertx\jphp\core\http\HttpServer::requestHandler. As requests arrive on the server the handler will be called with the requests.

You receive WebSockets by providing a @see \io\vertx\jphp\core\http\HttpServer::websocketHandler. As WebSocket connections arrive on the server, the WebSocket is passed to the handler.

package

Default

Methods

__construct

__construct() 

The actual port the server is listening on. This is useful if you bound the server specifying 0 as port number signifying an ephemeral port

actualPort() : integer

Response

integer

the actual port the server is listening on.

Close the server. Any open HTTP connections will be closed.

close( $arg0 = null) : void

The close happens asynchronously and the server may not be closed until some time after the call has returned. close() Like @see \io\vertx\jphp\core\http\HttpServer::close but supplying a handler that will be called when the server is actually closed (or has failed). param $completionHandler [callable] the handler close($completionHandler)

Arguments

$arg0

callable

Set a connection handler for the server.

connectionHandler( $arg0) : $this

Arguments

$arg0

callable

Response

$this

a reference to this, so the API can be used fluently

Set an exception handler called for socket errors happening before the HTTP connection is established, e.g during the TLS handshake.

exceptionHandler( $arg0) : $this

Arguments

$arg0

callable

Response

$this

a reference to this, so the API can be used fluently

Whether the metrics are enabled for this measured object

isMetricsEnabled() : boolean

Response

boolean

{@code true} if metrics are enabled

Tell the server to start listening. The server will listen on the port and host specified in the

listen( $arg0 = null,  $arg1 = null,  $arg2 = null) : $this
see \io\vertx\jphp\core\http\HttpServerOptions

that was used when creating the server.

The listen happens asynchronously and the server may not be listening until some time after the call has returned. listen() Like @see \io\vertx\jphp\core\http\HttpServer::listen but the server will listen on host "0.0.0.0" and port specified here ignoring any value in the @see \io\vertx\jphp\core\http\HttpServerOptions that was used when creating the server. param $port [integer] the port to listen on listen($port) Like @see \io\vertx\jphp\core\http\HttpServer::listen but supplying a handler that will be called when the server is actually listening (or has failed). param $listenHandler [callable] the listen handler listen($listenHandler) Tell the server to start listening. The server will listen on the port and host specified here, ignoring any value set in the @see \io\vertx\jphp\core\http\HttpServerOptions that was used when creating the server.

The listen happens asynchronously and the server may not be listening until some time after the call has returned. param $port [integer] the port to listen on param $host [string] the host to listen on listen($port, $host) Tell the server to start listening on the given address supplying a handler that will be called when the server is actually listening (or has failed). param $address [SocketAddress] the address to listen on param $listenHandler [callable] the listen handler listen($address, $listenHandler) Like @see \io\vertx\jphp\core\http\HttpServer::listen but supplying a handler that will be called when the server is actually listening (or has failed). param $port [integer] the port to listen on param $listenHandler [callable] the listen handler listen($port, $listenHandler) Like @see \io\vertx\jphp\core\http\HttpServer::listen but supplying a handler that will be called when the server is actually listening (or has failed). param $port [integer] the port to listen on param $host [string] the host to listen on param $listenHandler [callable] the listen handler listen($port, $host, $listenHandler)

Arguments

$arg0

callable | integer | SocketAddress

$arg1

callable | string

$arg2

callable

Response

$this

a reference to this, so the API can be used fluently

Set the request handler for the server to <code>requestHandler</code>. As HTTP requests are received by the server, instances of @see \io\vertx\jphp\core\http\HttpServerRequest will be created and passed to this handler.

requestHandler( $arg0) : $this

Arguments

$arg0

callable

Response

$this

a reference to this, so the API can be used fluently

Return the request stream for the server. As HTTP requests are received by the server, instances of @see \io\vertx\jphp\core\http\HttpServerRequest will be created and passed to the stream .

requestStream() : \io\vertx\jphp\core\http\ReadStream<HttpServerRequest>

Response

\io\vertx\jphp\core\http\ReadStream

the request stream

Set the websocket handler for the server to <code>wsHandler</code>. If a websocket connect handshake is successful a new @see \io\vertx\jphp\core\http\ServerWebSocket instance will be created and passed to the handler.

websocketHandler( $arg0) : $this

Arguments

$arg0

callable

Response

$this

a reference to this, so the API can be used fluently

Return the websocket stream for the server. If a websocket connect handshake is successful a new @see \io\vertx\jphp\core\http\ServerWebSocket instance will be created and passed to the stream .

websocketStream() : \io\vertx\jphp\core\http\ReadStream<ServerWebSocket>

Response

\io\vertx\jphp\core\http\ReadStream

the websocket stream