Coder Social home page Coder Social logo

lyhiving / http-server Goto Github PK

View Code? Open in Web Editor NEW

This project forked from amphp/http-server

0.0 1.0 0.0 14.3 MB

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

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

License: MIT License

PHP 98.40% HTML 1.46% Shell 0.14%

http-server's Introduction

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\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();
    });
});
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 [email protected] instead of using the issue tracker.

License

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

http-server's People

Contributors

rdlowrey avatar trowski avatar bwoebi avatar kelunik avatar staabm avatar enumag avatar krlv avatar morrisonlevi avatar brstgt avatar ekinhbayar avatar peehaa avatar bzikarsky avatar nikic avatar tpunt avatar shouze avatar maxmeijer42 avatar samizdam avatar rlmumford avatar stefanotorresi avatar vlakarados avatar prolic avatar petemcfarlane avatar strayobject avatar ocramius avatar joshdifabio avatar j7mbo avatar gquemener avatar backendtea avatar zvax avatar dbalabka avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.