Skip to content
Please note that GitHub no longer supports Internet Explorer.

We recommend upgrading to the latest Microsoft Edge, Google Chrome, or Firefox.

Learn more
A non-blocking HTTP application server for PHP based on Amp.
Branch: master
Clone or download
Latest commit fc32336 Mar 8, 2019
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
docs Fix middleware example (#272) Feb 13, 2019
examples Adjust code style to PSR-2 Jan 20, 2019
resources Rename ./etc to ./resources Mar 13, 2018
src
test
.editorconfig
.gitattributes Remove examples and other files from exports Sep 21, 2018
.gitignore Add further request tests Mar 15, 2018
.gitmodules
.php_cs.dist
.phpstorm.meta.php Revert attribute changes, fixes #216 Feb 3, 2018
.travis.yml
CHANGELOG.md
LICENSE Happy 2019 Jan 20, 2019
README.md
composer.json Use Message in amphp/http 1.1 Mar 2, 2019
infection.json.dist Fix infection config Mar 15, 2018
phpunit.xml.dist

README.md

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\CallableRequestHandler;
use Amp\Http\Server\Server;
use Amp\Http\Server\Request;
use Amp\Http\Server\Response;
use Amp\Http\Status;
use Amp\Socket;
use Psr\Log\NullLogger;

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

Amp\Loop::run(function () {
    $sockets = [
        Socket\listen("0.0.0.0:1337"),
        Socket\listen("[::]:1337"),
    ];
    
    $server = new Server($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();
    });
});
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.

You can’t perform that action at this time.