amphp / amp

A non-blocking concurrency framework for PHP applications. 🐘
https://amphp.org/amp
MIT License
4.25k stars 257 forks source link

The docs not up to date? #433

Closed gusdecool closed 7 months ago

gusdecool commented 7 months ago

It looks like the docs not up to date?
This is my first time using AMPHP library and I found it difficult to understand how to use this library.

When I tried the example shown in README.md like in this link https://github.com/amphp/amp?tab=readme-ov-file#await

<?php

use Amp\Future;
use Amp\Http\Client\HttpClientBuilder;
use Amp\Http\Client\Request;

$httpClient = HttpClientBuilder::buildDefault();
$uris = [
    "google" => "https://www.google.com",
    "news"   => "https://news.google.com",
    "bing"   => "https://www.bing.com",
    "yahoo"  => "https://www.yahoo.com",
];

try {
    $responses = Future\await(array_map(function ($uri) use ($httpClient) {
        return Amp\async(fn () => $httpClient->request(new Request($uri, 'HEAD')));
    }, $uris));

    foreach ($responses as $key => $response) {
        printf(
            "%s | HTTP/%s %d %s\n",
            $key,
            $response->getProtocolVersion(),
            $response->getStatus(),
            $response->getReason()
        );
    }
} catch (Exception $e) {
    // If any one of the requests fails the combo will fail
    echo $e->getMessage(), "\n";
}

The class Amp\Future not even exist. Perhaps it was renamed or removed into something else?


Question

Where is the best place to look for the simplest and minimalist example to see this library in effect?

(no promises, but hopefully I can help to update the docs)

Bilge commented 7 months ago

https://github.com/amphp/amp/blob/3.x/src/Future.php

gusdecool commented 7 months ago

Ah i see. So when installing amphp/http-client: v4

composer.json

        "amphp/amp": "^2.6",
        "amphp/http-client": "^4.6",

It actually installed AMP v2. not the v3. I only known that after explicitly requiring "amphp/amp"

Thus why I did not find the AMP/FUTURE.

Thanks @Bilge . I'm closing this ticket.

Bilge commented 7 months ago

amphp/http-client v4 is not compatible with Amp v3. You need amphp/http-client v5.