PHP code example of vtitar / background-tasks-symfony

1. Go to this page and download the library: Download vtitar/background-tasks-symfony 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/ */

    

vtitar / background-tasks-symfony example snippets


$task = new BackgroundTask();
$task->setCreatedAt(new DateTimeImmutable());
...
$this->entityManager->persist($task);
$this->entityManager->flush();

public function __construct(
    private readonly BackgroundTaskManager      $backgroundTaskManager
){}

$params = [
    'request_id' => 123
];

$this->backgroundTaskManager->addNewTask(
    'tit.test.test', # service that will process task
    'handle', # function that will process task
    $params,
    '',
    null,
    50
);

$this->backgroundTaskManager->saveToDb();

public function handle(array $params): void
{
    $requestId = $params['request_id'];
    // do whatever you need
}