GithubHelp home page GithubHelp logo

staabm / amp Goto Github PK

View Code? Open in Web Editor NEW

This project forked from amphp/amp

0.0 3.0 0.0 2.42 MB

A non-blocking concurrency framework for PHP applications

License: MIT License

PHP 99.41% Makefile 0.26% Shell 0.33%

amp's Introduction

Amp Logo

Amp     

Amp is a non-blocking concurrency framework for PHP. It provides an event loop, promises and streams as a base for asynchronous programming.

Promises in combination with generators are used to build coroutines, which allow writing asynchronous code just like synchronous code, without any callbacks.

Installation

This package can be installed as a Composer dependency.

composer require amphp/amp

Documentation

Documentation can be found on amphp.org as well as in the ./docs directory.

Requirements

  • PHP 7.0+
Optional Extension Backends

Extensions are only needed if your app necessitates a high numbers of concurrent socket connections.

Examples

This simple example uses our Artax HTTP client to fetch multiple HTTP resources concurrently.

<?php

use Amp\Artax\Response;
use Amp\Loop;

require __DIR__ . '/../vendor/autoload.php';

Loop::run(function () {
    $uris = [
        "https://google.com/",
        "https://github.com/",
        "https://stackoverflow.com/",
    ];

    $client = new Amp\Artax\DefaultClient;
    $client->setOption(Amp\Artax\Client::OP_DISCARD_BODY, true);

    try {
        foreach ($uris as $uri) {
            $promises[$uri] = $client->request($uri);
        }

        $responses = yield $promises;

        foreach ($responses as $uri => $response) {
            print $uri . " - " . $response->getStatus() . $response->getReason() . PHP_EOL;
        }
    } catch (Amp\Artax\HttpException $error) {
        // If something goes wrong Amp will throw the exception where the promise was yielded.
        // The Client::request() method itself will never throw directly, but returns a promise.
        print $error->getMessage() . PHP_EOL;
    }
});

Further examples can be found in the ./examples directory of this repository as well as in the ./examples directory of our other libraries

Versioning

amphp/amp follows the semver semantic versioning specification like all other amphp packages.

Version Bug Fixes Until Security Fixes Until
2.x TBA TBA
1.x 2017-12-31 2018-12-31

Compatible Packages

Compatible packages should use the amphp topic on GitHub.

Security

If you discover any security related issues, please email [email protected] or [email protected] instead of using the issue tracker.

License

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

amp's People

Contributors

andrewcarteruk avatar andrey-yantsen avatar asm89 avatar bubach avatar bwoebi avatar ck99 avatar danack avatar daverandom avatar douggr avatar gitter-badger avatar grahamcampbell avatar joelwurtz avatar joshdifabio avatar jsor avatar kelunik avatar lt avatar lyrixx avatar mickaelandrieu avatar peehaa avatar rdlowrey avatar sedatsevgili avatar staabm avatar trowski avatar wyrihaximus avatar

Watchers

 avatar  avatar  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.