amphp / amp

A non-blocking concurrency framework for PHP applications. 🐘

Home Page:https://amphp.org/amp

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

The docs not up to date?

gusdecool opened this issue · comments

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)

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.

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