1
0
mirror of https://github.com/danog/amp.git synced 2024-11-30 04:29:08 +01:00
Go to file
2018-03-16 15:42:32 +02:00
docs Update gems for documentation 2018-01-27 20:13:19 +01:00
examples Fix code style 2018-01-08 22:00:15 +01:00
lib Return named classes 2018-01-27 19:47:46 +01:00
test Remove unused variables 2017-12-05 08:48:56 +01:00
travis Fix event extension installation 2017-12-19 18:27:18 +01:00
.editorconfig Fix .editorconfig 2017-07-29 22:21:50 +02:00
.gitattributes Fix example → examples in Git attributes 2017-04-16 21:58:11 +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 Automatically add \ for buitins (#186) 2017-11-29 13:36:50 +01:00
.travis.yml Define AMP_DEBUG through environment 2017-12-02 10:23:12 -06:00
CHANGELOG.md Prepare v2.0.6 2018-01-27 20:18:05 +01:00
composer.json Update contributing.md 2018-03-16 15:42:32 +02:00
CONTRIBUTING.md Update contributing.md 2018-03-16 15:42:32 +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 Fix potential issues when operating on destroyed uv handles in shutdown sequence 2017-05-16 18:17:12 +02:00
README.md Add syntax highlighting 2017-11-12 17:16:19 +01: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.