Download the PHP package modelslab/modelq without Composer
On this page you can find all versions of the php package modelslab/modelq. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download modelslab/modelq
More information about modelslab/modelq
Files in modelslab/modelq
Package modelq
Short Description A lightweight PHP task queue library, alternative to traditional queue systems, optimized for ML inference workloads
License MIT
Informations about the package modelq
ModelQ PHP
A lightweight PHP task queue library, alternative to traditional queue systems, optimized for ML inference workloads.
Features
- Simple API - Easy to use task registration and enqueueing
- Redis-backed - Fast and reliable task storage using Redis
- Streaming Support - Real-time streaming results for long-running tasks
- Remote Workers - Connect PHP frontend to Python GPU workers via Redis
- Middleware Hooks - Lifecycle hooks for monitoring and customization
- Delayed Tasks - Schedule tasks to run after a delay
- CLI Tools - Built-in commands for queue management
- ML Optimized - Designed for machine learning inference workloads
Use Case: PHP Frontend + Python GPU Worker
ModelQ PHP is designed to work seamlessly with Python ModelQ workers running on GPU servers. This enables you to:
- Run your PHP web application on standard servers
- Offload ML inference tasks to dedicated GPU servers running Python
- Share a managed Redis instance (AWS ElastiCache, GCP Memorystore, etc.)
Python Worker (GPU Server)
PHP Frontend (Web Server)
See examples/remote_worker.php for a complete example.
Requirements
- PHP 8.1 or higher
- Redis server
- phpredis extension (
ext-redis)
Installation
Make sure you have the phpredis extension installed:
Quick Start
1. Create a Worker
2. Enqueue Tasks
Usage
Basic Task Registration
Enqueueing Tasks
Custom Task IDs
By default, ModelQ generates a UUID for each task. You can provide your own task ID to correlate tasks with your database records:
This is useful when you want to:
- Track tasks using your existing database primary keys
- Easily correlate queue tasks with database records
- Look up task status without storing the generated UUID
Streaming Tasks
For tasks that produce incremental output (like ML text generation):
Queue Management
Task History & Monitoring
Track past tasks, view errors, and monitor remote workers:
Worker Info
Get detailed information about registered workers including system resources (CPU, RAM, GPU):
Worker info includes:
worker_id- Unique worker identifierstatus- Current status (idle, busy)allowed_tasks- List of tasks this worker handleslast_heartbeat- Unix timestamp of last heartbeathostname- Worker hostnameos- Operating system infopython_version- Python version (for Python workers)php_version- PHP version (for PHP workers)system_info- Detailed CPU, RAM, and GPU information
Delayed Tasks
Middleware
Create custom middleware for lifecycle hooks:
Custom Redis Client
Error Handling
CLI Commands
ModelQ includes CLI commands for queue management:
The app.php file should return a configured ModelQ instance:
Configuration Options
Task Options
Architecture
Redis Keys
ModelQ uses the following Redis keys:
| Key Pattern | Type | Description |
|---|---|---|
task_queue |
List | Main task queue |
task:{id} |
String | Task data |
task_result:{id} |
String | Task result |
task_stream:{id} |
Stream | Streaming task output |
servers |
Hash | Registered worker servers |
processing_tasks |
Set | Currently processing tasks |
delayed_tasks |
Sorted Set | Delayed tasks (score = execution time) |
Testing
Examples
Check the examples/ directory for complete working examples:
examples/basic_usage.php- Basic task queue operationsexamples/producer.php- Enqueueing tasks and getting resultsexamples/worker.php- Worker process setupexamples/streaming_example.php- Streaming task exampleexamples/middleware_example.php- Custom middleware usageexamples/queue_management.php- Queue management operationsexamples/remote_worker.php- PHP + Remote Python GPU Worker
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
License
This project is licensed under the MIT License - see the LICENSE file for details.
Related Projects
- ModelQ Python - The original Python implementation
All versions of modelq with dependencies
ext-redis Version *
symfony/console Version ^6.0|^7.0
psr/log Version ^3.0