PHP code example of tourze / doctrine-async-insert-bundle

1. Go to this page and download the library: Download tourze/doctrine-async-insert-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/ */

    

tourze / doctrine-async-insert-bundle example snippets


return [
    // ... other bundles
    Tourze\DoctrineAsyncInsertBundle\DoctrineAsyncInsertBundle::class => ['all' => true],
];



use Tourze\DoctrineAsyncInsertBundle\Service\AsyncInsertService;

/** @var AsyncInsertService $asyncInsertService */
$asyncInsertService = $container->get(AsyncInsertService::class);

// Insert entity asynchronously
$entity = new YourEntity();
$entity->setName('example');

$asyncInsertService->asyncInsert($entity);



// Insert with 5-second delay
$asyncInsertService->asyncInsert($entity, 5000);

// Allow duplicate entries
$asyncInsertService->asyncInsert($entity, 0, true);



use Tourze\DoctrineAsyncInsertBundle\Message\InsertTableMessage;

// Create an insert message manually
$message = new InsertTableMessage();
$message->setTableName('your_table');
$message->setParams([
    'column1' => 'value1',
    'column2' => ['array', 'will', 'be', 'json_encoded'],
]);
$message->setAllowDuplicate(false);

// Dispatch the message using Symfony Messenger
$messageBus->dispatch($message);