amphp / http-server

An advanced async HTTP server library for PHP, perfect for real-time apps and APIs with high concurrency demands.
https://amphp.org/http-server
MIT License
1.29k stars 100 forks source link

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

Closed chengyu-luna closed 2 years ago

chengyu-luna commented 3 years ago

`<?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();
});

});`

kelunik commented 3 years ago

That class is part of amphp/socket.