[RESOLU] Comment installer Spatie\Async?

sario
Invité n'ayant pas de compte PHPfrance

18 avr. 2022, 13:40

Bonjour,

J'ai une installation XAMPP avec Php 8.

J'essaye de tester les fonctions async en php via ce package:
https://github point com /spatie/async/ (je ne peux pas mettre le lien)

J'ai installé composer depuis leur site, ensuite j'ai lancé un PowerShell puis
 cd C:\xampp\htdocs      
composer require spatie/async
Ensuite j'ai juste copié leur example dans un fichier test.php

use Spatie\Async\Pool;

$pool = Pool::create();

foreach ($things as $thing) {
    $pool->add(function () use ($thing) {
        // Do a thing
    })->then(function ($output) {
        // Handle success
    })->catch(function (Throwable $exception) {
        // Handle exception
    });
}

$pool->wait();
Mais j'ai ce message d'erreur sur ma page php:

Fatal error: Uncaught Error: Class "Spatie\Async\Pool" not found in C:\xampp\htdocs\test.php:35 Stack trace: #0 {main} thrown in C:\xampp\htdocs\test.php on line 35

Il n'est pas détecté malgré l'installation avec composer require... Comment puis-je installer correctement Spatie/Async? :?:

Merci

ynx
Mammouth du PHP | 586 Messages

19 avr. 2022, 10:08

Bonjour,

Il faut inclure le fichier autoload de Composer (chemin à vérifier) :
<?php

require __DIR__ . '/vendor/autoload.php';

use Spatie\Async\Pool;

$pool = Pool::create();


sario
Invité n'ayant pas de compte PHPfrance

19 avr. 2022, 22:19

Parfait! c'est bon! Merci :D