HttpServer

Purpose of this Component

This component is responsible for parsing incoming HTTP requests. It's purpose is to buffer data until it receives a full HTTP header request and pass it on. You can use this as a raw HTTP server (not advised) but it's meant for upgrading WebSocket requests.

Note: This component is bundled within the App class.

Events triggered by this Component

As found in the API Docs: Triggered events are propagated through a HttpServerInterface object passed to the __construct.

  • onOpen (ConnectionInterface $conn, RequestInterface $request = null) - A new client connection has been opened
  • onClose (ConnectionInterface $conn) - A client connection is about to, or has closed
  • onError (ConnectionInterface $from, Exception $error) - An error has occurred with a Connection

Functions callable on Connections

  • send (string $message) - Send a message (string) to the client
  • close - Gracefully close the connection to the client

Wraps other components nicely

Wrapped by other components nicely

Usage

<?php
// Your shell script
use Ratchet\Http\HttpServer;
use Ratchet\Server\IoServer;

    $http = new HttpServer(new MyWebPage);

    $server = IoServer::factory($http);
    $server->run();