amphp / http-server

An advanced async HTTP server library for PHP, perfect for real-time apps and APIs with high concurrency demands.

Home Page:https://amphp.org/http-server

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

The use Amp\Socket\Server namespace in the document example does not exist

chengyu-luna opened this issue · comments

`<?php

use Amp\Http\Server\RequestHandler\CallableRequestHandler;
use Amp\Http\Server\HttpServer;
use Amp\Http\Server\Request;
use Amp\Http\Server\Response;
use Amp\Http\Status;
use Amp\Socket\Server;
use Psr\Log\NullLogger;

// Run this script, then visit http://localhost:1337/ in your browser.

Amp\Loop::run(function () {
$sockets = [
Server::listen("0.0.0.0:1337"),
Server::listen("[::]:1337"),
];

$server = new HttpServer($sockets, new CallableRequestHandler(function (Request $request) {
    return new Response(Status::OK, [
        "content-type" => "text/plain; charset=utf-8"
    ], "Hello, World!");
}), new NullLogger);

yield $server->start();

// Stop the server gracefully when SIGINT is received.
// This is technically optional, but it is best to call Server::stop().
Amp\Loop::onSignal(SIGINT, function (string $watcherId) use ($server) {
    Amp\Loop::cancel($watcherId);
    yield $server->stop();
});

});`

That class is part of amphp/socket.