1
0
mirror of https://github.com/danog/amp.git synced 2024-11-26 20:15:00 +01:00
Go to file
2018-11-25 18:00:57 +01:00
docs Fix syntax error in documentation example (#237) 2018-09-20 07:17:57 +02:00
examples Apply PSR-2 2018-06-18 20:00:01 +02:00
lib Add timeoutWithDefault function (#245) 2018-11-25 17:56:42 +01:00
test Add timeoutWithDefault function (#245) 2018-11-25 17:56:42 +01:00
travis Prevent ext-event 2.4.0RC1 and use 2.3.0 instead 2018-04-30 22:47:14 +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 Define AMP_DEBUG through environment 2017-12-02 10:23:12 -06:00
CHANGELOG.md Add changelog entry for 2.0.7 2018-04-30 10:43:43 +02:00
composer.json Update contributing.md 2018-03-16 15:42:32 +02:00
CONTRIBUTING.md Apply PSR-2 2018-06-18 20:00:01 +02:00
LICENSE Update copyright (#242) 2018-11-25 18:00:57 +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 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.