A flexible PHP queue management system supporting multiple backend drivers.
- Multiple queue backend support
- Redis
- MariaDB
- PostgreSQL
- SQLite
- Beanstalkd
- Robust job processing
- Configurable retry mechanisms
- Extensible architecture
Install the package using Composer:
composer require tudorr89/phpqdrv
- PHP 8.1+
- Supported database extensions based on chosen driver
<?php
use Predis\Client;
use Tudorr89\Phpqdrv\QueueFactory;
use Tudorr89\Phpqdrv\Worker;
// Create Redis connection
$redis = new Client([
'host' => '127.0.0.1',
'port' => 6379
]);
// Create queue instance
$queue = QueueFactory::createRedisQueue($redis);
// Enqueue a job
$job = $queue->push('emails', [
'to' => '[email protected]',
'subject' => 'Welcome',
'body' => 'Hello World!'
]);
// Create a worker
$worker = new Worker($queue);
// Process jobs
$worker->work('emails', function($payload) {
sendEmail(
$payload['to'],
$payload['subject'],
$payload['body']
);
});
<?php
use PDO;
use Tudorr89\Phpqdrv\QueueFactory;
use Tudorr89\Phpqdrv\Worker;
// Create PDO connection
$pdo = new PDO(
'pgsql:host=localhost;dbname=mydb',
'username',
'password'
);
// Create queue instance
$queue = QueueFactory::createPostgreSQLQueue($pdo);
// Similar job enqueuing and processing as Redis example
<?php
use Net_Beanstalkd;
use Tudorr89\Phpqdrv\QueueFactory;
use Tudorr89\Phpqdrv\Worker;
// Create Beanstalkd connection
$beanstalkd = new Net_Beanstalkd('localhost', 11300);
// Create queue instance
$queue = QueueFactory::createBeanstalkdQueue($beanstalkd);
// Similar job enqueuing and processing as previous examples
// Customize worker behavior
$worker = new Worker(
$queue,
$maxAttempts = 3, // Maximum job retry attempts
$sleepTime = 5 // Seconds to wait between job checks
);
Each queue driver implements these core methods:
push(string $queue, array $payload)
: Add a new job to the queuepop(string $queue)
: Retrieve and remove a job from the queueack(JobInterface $job)
: Acknowledge successful job completionfail(JobInterface $job)
: Mark a job as failedcount(string $queue)
: Count pending jobs in a queue
- Configurable max retry attempts
- Automatic job failure after max attempts
- Supports logging and custom error handling
- Improved logging
- More sophisticated retry strategies
- Advanced job scheduling
- Distributed queue support
- Fork the repository
- Create your feature branch (
git checkout -b feature/AmazingFeature
) - Commit your changes (
git commit -m 'Add some AmazingFeature'
) - Push to the branch (
git push origin feature/AmazingFeature
) - Open a Pull Request
Distributed under the MIT License. See LICENSE
for more information.
If you encounter any issues or have questions, please file an issue on the GitHub repository.