@@ -23,6 +23,7 @@ A production-ready Raw PHP REST API Starter Kit with JWT authentication, user ma
2323- ✅ ** Debug Bar** - Development debugging toolbar with performance monitoring
2424- ✅ ** CLI Support** - Command-line interface for development tasks
2525- ✅ ** API Versioning** - Multiple API versions with backward compatibility
26+ - ✅ ** Queue System** - Background job processing with Redis/Database drivers
2627
2728## 📁 Project Structure
2829
@@ -41,6 +42,10 @@ A production-ready Raw PHP REST API Starter Kit with JWT authentication, user ma
4142│ ├── helpers/ # Utility classes
4243│ ├── middleware/ # Request middleware
4344│ ├── models/ # Data models
45+ │ ├── queue/ # Queue system
46+ │ │ ├── Drivers/ # Queue drivers (Database, Redis)
47+ │ │ ├── Jobs/ # Job classes
48+ │ │ └── Processors/ # Queue workers
4449│ ├── routes/ # Route definitions
4550│ │ ├── api.php # Legacy API routes (backward compatibility)
4651│ │ ├── api_v1.php # Version 1 API routes
@@ -78,6 +83,14 @@ DEBUGBAR_ENABLED=true
7883DEBUGBAR_ALLOWED_IPS=127.0.0.1,::1
7984```
8085
86+ ** Queue System Configuration (Optional)**
87+ ``` bash
88+ # Queue driver (database or redis)
89+ QUEUE_DRIVER=database
90+ REDIS_HOST=127.0.0.1
91+ REDIS_PORT=6379
92+ ```
93+
8194### 3. Database Setup
8295``` bash
8396# Option 1: Import the complete database schema
@@ -382,6 +395,118 @@ curl -H "Accept: application/vnd.api+json;version=2" http://localhost:8000/api/u
382395- Maintain at least 2 versions simultaneously
383396- Provide migration guides for version changes
384397
398+ ## 🔄 Queue System
399+
400+ The framework includes a powerful queue system for background job processing with support for multiple drivers.
401+
402+ ### Features
403+ - ** Background Job Processing** - Asynchronous task execution
404+ - ** Multiple Drivers** - Database and Redis support
405+ - ** Email Queues** - Reliable email delivery
406+ - ** File Processing** - Image resize, file conversion, compression
407+ - ** Job Retry Logic** - Automatic retry with exponential backoff
408+ - ** Failed Job Handling** - Dead letter queue for failed jobs
409+ - ** CLI Workers** - Command-line queue processors
410+
411+ ### Configuration
412+
413+ Add to your ` .env ` file:
414+ ``` bash
415+ # Queue driver (database or redis)
416+ QUEUE_DRIVER=database
417+
418+ # Redis configuration (if using Redis driver)
419+ REDIS_HOST=127.0.0.1
420+ REDIS_PORT=6379
421+ ```
422+
423+ ### Usage
424+
425+ #### Dispatching Jobs
426+ ``` php
427+ // Email jobs
428+ queue_email('user@example.com', 'Welcome!', 'Welcome message');
429+
430+ // File processing jobs
431+ queue_file_processing('/path/to/image.jpg', 'resize', ['width' => 800, 'height' => 600]);
432+
433+ // Custom jobs
434+ use App\Queue\Jobs\SendEmailJob;
435+ $job = new SendEmailJob('user@example.com', 'Subject', 'Message');
436+ dispatch($job, 'emails');
437+ ```
438+
439+ #### Processing Jobs
440+ ``` bash
441+ # Start queue worker
442+ php console queue work default
443+
444+ # Process specific queue
445+ php console queue work emails
446+
447+ # Process limited number of jobs
448+ php console queue work files 10
449+
450+ # Check queue status
451+ php console queue status emails
452+ ```
453+
454+ ### Built-in Job Types
455+
456+ ** SendEmailJob** - Email delivery
457+ - Automatic retry on failure
458+ - SMTP configuration support
459+ - HTML/text email support
460+
461+ ** ProcessFileJob** - File processing
462+ - Image resizing
463+ - File compression
464+ - Format conversion
465+ - Batch processing support
466+
467+ ### Creating Custom Jobs
468+
469+ ``` php
470+ use App\Queue\Jobs\BaseJob;
471+
472+ class CustomJob extends BaseJob
473+ {
474+ private $data;
475+
476+ public function __construct($data)
477+ {
478+ $this->data = $data;
479+ $this->maxRetries = 3;
480+ $this->delay = 30; // seconds
481+ }
482+
483+ public function handle(): bool
484+ {
485+ // Your job logic here
486+ return true;
487+ }
488+
489+ public function failed(\Exception $exception): void
490+ {
491+ // Handle job failure
492+ }
493+ }
494+ ```
495+
496+ ### Queue Drivers
497+
498+ ** Database Driver**
499+ - Uses MySQL/PostgreSQL for job storage
500+ - Automatic table creation
501+ - Transaction support
502+ - No external dependencies
503+
504+ ** Redis Driver**
505+ - High performance
506+ - Atomic operations
507+ - Delayed job support
508+ - Requires Redis extension
509+
385510## 💻 CLI Support
386511
387512The framework includes a powerful command-line interface for development tasks.
@@ -405,6 +530,11 @@ php console cache clear
405530php console make controller ControllerName
406531php console make model ModelName
407532
533+ # Queue management
534+ php console queue work [queue] [max-jobs]
535+ php console queue status [queue]
536+ php console queue clear [queue]
537+
408538# Show help
409539php console help
410540```
@@ -429,6 +559,12 @@ php console test app/tests/Unit/UserTest.php
429559
430560# Clear application cache
431561php console cache clear
562+
563+ # Start queue worker
564+ php console queue work emails
565+
566+ # Check queue status
567+ php console queue status default
432568```
433569
434570## 🧪 Testing
0 commit comments