PHP code example of quazardous / gramphp-bundle

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

    

quazardous / gramphp-bundle example snippets


use Quazardous\GramPHP\Driver\Mariadb\Query;
use Quazardous\GramPHP\Driver\Mariadb\Transaction;
use Quazardous\GramPHP\NodeJournal;

final class ShipWorker
{
    public function __construct(
        private readonly NodeJournal $ordersJournal,
        private readonly Transaction $transaction,     // retries a unit on a deadlock
    ) {}

    public function __invoke(): void
    {
        $lease = $this->transaction->run(fn() => $this->ordersJournal->claim(
            'ship', 50, new Query('SELECT id FROM orders WHERE paid = 1 ORDER BY id'),
        ));
        foreach ($lease as $orderId) {
            // … ship it …
        }
        $this->transaction->run(fn() => $this->ordersJournal->conclude('ship', $lease, $lease->token));
    }
}
yaml
# config/packages/doctrine.yaml
doctrine:
    dbal:
        options:
            !php/const PDO::MYSQL_ATTR_INIT_COMMAND: 'SET SESSION TRANSACTION ISOLATION LEVEL READ COMMITTED'