Core concepts

Handling HTTP Requests

In OpenSwoole, WebSockets extends the HTTP Server.


The Conveyor Server has some customization points. That said, you can add an HTTP handler and make it able to handle HTTP requests and serve your website with it or any HTTP interface with it.

Here, we use the Conveyor Server Events. To know more, you can check here: Conveyor Server Events.

Here is an example of how to do that:

1<?php
2
3use Conveyor\ConveyorServer;
4use OpenSwoole\Http\Request;
5use OpenSwoole\Http\Response;
6use Conveyor\Events\PreServerStartEvent;
7
8$listeners = [
9    ConveyorServer::EVENT_PRE_SERVER_START => fn (PreServerStartEvent $event) => 
10        $event->server->on('request', function (Request $request, Response $response) {
11           $response->end('Hello World!');
12        }),
13];
14
15ConveyorServer::start(eventListeners: $listeners);
Previous
Conveyor SubProtocol