PHP code example of tobento / app-queue

1. Go to this page and download the library: Download tobento/app-queue 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/ */

    

tobento / app-queue example snippets


use Tobento\App\AppFactory;
use Tobento\Service\Queue\QueueInterface;
use Tobento\Service\Queue\QueuesInterface;
use Tobento\Service\Queue\JobProcessorInterface;
use Tobento\Service\Queue\FailedJobHandlerInterface;

// Create the app
$app = (new AppFactory())->createApp();

// Add directories:
$app->dirs()
    ->dir(realpath(__DIR__.'/../'), 'root')
    ->dir(realpath(__DIR__.'/../app/'), 'app')
    ->dir($app->dir('app').'config', 'config', group: 'config')
    ->dir($app->dir('root').'public', 'public')
    ->dir($app->dir('root').'vendor', 'vendor');

// Adding boots
$app->boot(\Tobento\App\Queue\Boot\Queue::class);
$app->booting();

// Implemented interfaces:
$queue = $app->get(QueueInterface::class);
$queues = $app->get(QueuesInterface::class);
$jobProcessor = $app->get(JobProcessorInterface::class);
$failedJobHandler = $app->get(FailedJobHandlerInterface::class);

// Run the app
$app->run();

// Get and run the application.
// ()->run();
app/config/queue.php

php app queue:work

use Tobento\Service\Queue\FailedJobHandlerInterface;

$app->on(FailedJobHandlerInterface::class, function (): FailedJobHandlerInterface {
    return new CustomFailedJobHandler();
});