Download the PHP package stietotalwin/stw-sdk-php-redis-queue without Composer
On this page you can find all versions of the php package stietotalwin/stw-sdk-php-redis-queue. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download stietotalwin/stw-sdk-php-redis-queue
More information about stietotalwin/stw-sdk-php-redis-queue
Files in stietotalwin/stw-sdk-php-redis-queue
Package stw-sdk-php-redis-queue
Short Description Redis Queue library for CodeIgniter framework
License MIT
Informations about the package stw-sdk-php-redis-queue
StieTotalWin Redis Queue
A generic Redis-based queue library for CodeIgniter 4 framework that provides reliable job processing with support for delayed jobs, retries, and failure handling.
Features
- Job Publishing: Publish jobs to Redis queues with optional delays
- Job Consumption: Consume and process jobs from queues
- Retry Mechanism: Automatic retry with exponential backoff for failed jobs
- Multiple Queues: Support for multiple named queues
- Queue Management: Monitor queue statistics, clear queues, and manage jobs
- Bulk Operations: Publish multiple jobs at once
- Failed Job Handling: Track and retry failed jobs
- Job Expiration: Automatic cleanup of expired jobs
- CodeIgniter 4 Integration: Built specifically for CodeIgniter 4 framework
- Unified Configuration: Single Redis configuration for all operations
Requirements
- PHP ^8.5
- CodeIgniter 4 >= 4.7
- Redis server
- Predis client library
Installation
Install via Composer:
Upgrading from 0.1.x to 2.0
2.0 raises the platform floor and fixes three queue-correctness bugs. There are no
application API changes — publish(), consume(), markCompleted() and
markFailed() keep their existing signatures.
- PHP ^8.5 and CodeIgniter ^4.7 are now required. All implicitly-nullable
parameters were made explicit, so the library runs deprecation-free on 8.5.
CodeIgniter below 4.7 pulls a
laminas/laminas-escaperthat refuses to install on PHP 8.5. - A job that is out of attempts is never run again. Queue recovery previously
only recognised a dead job when its stored status read
failed.markFailed()sets that status on its in-memory copy only, so an interrupted terminal transition left the stored entry readingprocessingand the job was requeued on everyconsume(), forever, appending a dead-letter record each time. Recovery now decides on attempts alone. republishStuckJobs()no longer resurrects exhausted jobs. It incrementedattemptswith no upper bound; it now dead-letters a job that cannot retry.- A job can only ever be owned by one worker.
BZPOPMINand the validation script are separate round-trips, so recovery could hand an in-flight job to a second worker and the same job would run twice. The script now claims the job atomically and a duplicate claim is dropped.
After upgrading, restart your workers — long-running consumers keep the code
they started with, so a composer update alone changes nothing.
Configuration
Create a configuration file app/Config/RedisQueue.php:
Configuration for Cloud Redis (e.g., Upstash)
Usage
Publishing Jobs
Consuming Jobs
Queue Management
Failed Job Management
Job Object Properties
The Job class provides access to job information:
Queue Structure
The library uses the following Redis data structures:
{queue_name}: Sorted set for pending jobs (score = process_at timestamp){queue_name}:jobs: Hash map storing job data (key = job_id, value = job_json){queue_name}:processing: Sorted set for jobs currently being processed{queue_name}:failed: List of failed jobs that exceeded max attempts{queue_name}:lost: List of jobs that were lost during processing (for recovery)
Configuration Options
| Option | Default | Description |
|---|---|---|
scheme |
tcp |
Redis connection scheme (tcp, tls, unix) |
host |
127.0.0.1 |
Redis server host |
port |
6379 |
Redis server port |
user |
null |
Redis username (for cloud services) |
password |
null |
Redis password (if required) |
database |
null |
Redis database number (optional for cloud) |
parameters |
[] |
Additional Predis client parameters |
defaultQueue |
default |
Default queue name |
maxAttempts |
3 |
Maximum retry attempts for failed jobs |
retryDelay |
60 |
Base retry delay in seconds |
jobTtl |
86400 |
Job time-to-live in seconds |
cleanupInterval |
3600 |
Cleanup interval in seconds |
Advanced Features
Job Recovery and Maintenance
The library includes advanced recovery and maintenance features:
- Stuck Job Detection: Automatically detects jobs that have been processing for too long
- Lost Job Recovery: Recovers jobs that were lost due to crashes or interruptions
- Memory-Efficient Cleanup: Uses HSCAN for batch processing to handle large datasets
- Comprehensive Statistics: Provides detailed recovery and cleanup statistics
- Automatic Queue Consistency: Ensures data structure consistency and recovery
Memory Management
The consumer includes built-in memory monitoring:
- Memory Usage Tracking: Monitors PHP memory usage during operations
- Batch Processing: Processes jobs in configurable batches to prevent memory exhaustion
- Explicit Cleanup: Explicitly releases memory after processing large datasets
- Warning System: Logs warnings when memory usage approaches limits
Atomic Operations
The library uses Lua scripts for atomic operations to ensure data consistency:
- Atomic Job Consumption: Jobs are atomically moved from pending to processing
- Consistency Checks: Validates job data exists before processing
- Race Condition Prevention: Prevents multiple consumers from processing the same job
Error Handling
The library provides robust error handling:
- Automatic Retries: Failed jobs are automatically retried with exponential backoff
- Failed Job Storage: Jobs that exceed max attempts are stored in a failed jobs list
- Error Messages: Exception messages are captured and stored with failed jobs
- Job Expiration: Old jobs are automatically cleaned up to prevent memory leaks
Best Practices
- Use Specific Queue Names: Create separate queues for different job types
- Handle Exceptions: Always wrap job processing in try-catch blocks
- Monitor Failed Jobs: Regularly check and handle failed jobs
- Set Appropriate TTL: Configure job TTL based on your use case
- Clean Up Regularly: Use the cleanup functionality to remove expired jobs
- Use Delays Wisely: For time-sensitive jobs, use delays instead of immediate processing
- Secure Connections: Use TLS scheme for production Redis connections
- Connection Pooling: Consider using connection pooling for high-throughput applications
- Monitor Memory Usage: Enable detailed logging during development to monitor memory usage
- Run Recovery Operations: Periodically check and run recovery operations for stuck jobs
- Batch Processing: Use appropriate batch sizes for cleanup operations on large queues
- Data Validation: Always validate and decode JSON data from jobs before processing
License
This library is licensed under the MIT License. See the LICENSE file for details.
Support
For issues and questions, please contact: [email protected]
All versions of stw-sdk-php-redis-queue with dependencies
predis/predis Version ^3.1
ramsey/uuid Version ^4.2
codeigniter4/framework Version ^4.7