1
0
mirror of https://github.com/danog/amp.git synced 2024-11-26 20:15:00 +01:00
Go to file
2018-12-25 14:05:19 +01:00
docs Update code style in docs 2018-06-18 20:11:15 +02:00
examples Fix code style 2018-07-24 18:12:01 +02:00
lib Remove outdated / unused code 2018-10-08 18:39:44 +02:00
test Remove outdated / unused code 2018-10-08 18:39:44 +02:00
travis Install ext-async on Travis 2018-07-24 18:00:42 +02:00
.editorconfig Fix .editorconfig 2017-07-29 22:21:50 +02:00
.gitattributes Ignore docs/asset on export 2018-05-16 22:29:53 +02:00
.gitignore Added further Internal\Producer tests 2017-05-02 18:10:10 +02:00
.gitmodules Update to new shared repository 2017-09-27 13:25:40 +02:00
.php_cs.dist Apply PSR-2 2018-06-18 20:00:01 +02:00
.travis.yml Fix composer.json 2018-12-25 14:05:19 +01:00
CHANGELOG.md Add changelog entry for 2.0.7 2018-04-30 10:43:43 +02:00
composer.json Fix composer.json 2018-12-25 14:05:19 +01:00
CONTRIBUTING.md Apply PSR-2 2018-06-18 20:00:01 +02:00
LICENSE Fix copyright dates 2017-03-12 12:38:18 +01:00
Makefile Add Makefile that automatically setups, runs tests and checks code style 2017-05-04 08:44:44 +02:00
phpunit.xml.dist Remove outdated / unused code 2018-10-08 18:39:44 +02:00
README.md Update README 2018-04-30 22:49:57 +02:00

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 bobwei9@hotmail.com or me@kelunik.com instead of using the issue tracker.

License

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