xtrime-ru / http-server

A non-blocking HTTP application server for PHP based on Amp.

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

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

HTTP Server

Build Status License

This package provides a non-blocking HTTP/1.1 and HTTP/2 application server written in PHP based on Amp. Several features are provided in separate packages, such as the WebSocket component.

The packages was previously named amphp/aerys, but has been renamed to be easier to remember, as many people were having issues with the old name.

Features

Requirements

  • PHP 7

Installation

composer require amphp/http-server

Documentation

Example

<?php

use Amp\Http\Server\RequestHandler\ClosureRequestHandler;
use Amp\Http\Server\SocketHttpServer;
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 SocketHttpServer($sockets, new ClosureRequestHandler(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();
    });
});
php example.php

Contributing

Please read CONTRIBUTING.md for details on our code of conduct, and the process for submitting pull requests to us.

Security

If you discover any security related issues, please email contact@amphp.org instead of using the issue tracker.

License

The MIT License (MIT). Please see LICENSE for more information.

About

A non-blocking HTTP application server for PHP based on Amp.

https://amphp.org/http-server

License:MIT License


Languages

Language:PHP 98.2%Language:HTML 1.7%Language:Shell 0.2%