PHP code example of hasel / aphpsurd-bundle

1. Go to this page and download the library: Download hasel/aphpsurd-bundle library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

hasel / aphpsurd-bundle example snippets


// config/bundles.php
return [
    Hasel\AphpsurdBundle\AphpsurdBundle::class => ['all' => true],
];

use Hasel\AphpsurdBundle\Attribute\AsAbsurdTask;
use Ruudk\Absurd\Task\Context;

#[AsAbsurdTask('send-invitations', queue: 'notifications')]
final class SendInvitationsTask
{
    public function __invoke(SendInvitationsPayload $params, Context $ctx): mixed
    {
        // ...
    }
}

use Hasel\AphpsurdBundle\AbsurdClientInterface;

final class OrderController
{
    public function __construct(private AbsurdClientInterface $absurd) {}

    public function checkout(): Response
    {
        $this->absurd->spawn(new SendInvitationsPayload($orderId));
        $this->absurd->emitEvent('order.confirmed', ['orderId' => $id]);
        // ...
    }
}

$this->absurd->spawn(SendInvitationsTask::class, $payload);

use Ruudk\Absurd\Task\SpawnOptions;

$this->absurd->spawn(new SendInvitationsPayload($orderId), options: new SpawnOptions(maxAttempts: 1));
bash
php bin/console absurd:consume
php bin/console absurd:consume --queue=notifications
php bin/console absurd:consume --limit=100 --time-limit=3600 --memory-limit=128M
bash
php bin/console absurd:migrate
php bin/console absurd:migrate --dry-run  # list pending files without applying