1. Go to this page and download the library: Download tina4stack/tina4php-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/ */
tina4stack / tina4php-queue example snippets
$config = new \Tina4\QueueConfig();
$config->queueType = 'litequeue';
$config->litequeueDatabaseName = 'queue.db';
$queue = new \Tina4\Queue($config, 'my-topic');
$producer = new \Tina4\Producer($queue);
$msg = $producer->produce('Hello World', 'user123');
echo "Produced: {$msg->messageId}\n";
foreach ($queue->consume(acknowledge: true) as $msg) {
echo "Received: {$msg->data} from user {$msg->userId}\n";
}
$gen = $queue->consume();
$msg = $gen->current(); // Get one message, or wait for one
$queue1 = new \Tina4\Queue($config, 'orders');
$queue2 = new \Tina4\Queue($config, 'notifications');
$consumer = new \Tina4\Consumer([$queue1, $queue2], acknowledge: true, pollInterval: 0.5);
foreach ($consumer->messages() as $msg) {
echo "From {$msg->topic}: {$msg->data}\n";
}
$consumer = new \Tina4\Consumer($queue);
$consumer->runForever(function (\Tina4\QueueMessage $msg) {
// Process each message
echo "Handling: {$msg->data}\n";
});
$queue = new \Tina4\Queue($config, 'bulk-jobs', batchSize: 10);
foreach ($queue->consume() as $msg) {
// Up to 10 messages fetched per poll
processJob($msg);
}