This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
# Install dependencies
composer install
# Run all tests (requires Redis running on localhost:6379)
./vendor/bin/phpunit
# Run only unit tests (no Redis required)
./vendor/bin/phpunit --testsuite Unit
# Run only integration tests (requires Redis)
./vendor/bin/phpunit --testsuite Integration
# Run a single test class
./vendor/bin/phpunit --filter TaskTest
# Run a single test method
./vendor/bin/phpunit --filter testTaskCreation
# Static analysis
composer analyse
# or: ./vendor/bin/phpstan analyse src --level=6
# CLI commands (require app-path that returns ModelQ instance)
./bin/modelq status <app-path>
./bin/modelq list-queued <app-path>
./bin/modelq clear-queue <app-path>
./bin/modelq remove-task <app-path> <task-id>
./bin/modelq run-workers <app-path> --workers=4ModelQ PHP is a Redis-backed task queue designed to work with Python ModelQ workers on GPU servers. PHP acts as the producer (web frontend), Python as the consumer (ML inference).
-
src/ModelQ.php- Main orchestrator. Handles Redis connection, task registration (task()), enqueueing (enqueue()), worker loop (startWorkers()), and queue management methods. Uses phpredis extension. -
src/Task/Task.php- Task representation with UUID generation, serialization (toArray()/fromArray()), result polling (getResult()), and streaming support (getStream()uses Redis Streams viaxRead). -
src/Middleware/Middleware.php- Abstract base class for lifecycle hooks:beforeEnqueue,afterEnqueue,onError,onTimeout,beforeWorkerBoot, etc. -
src/Console/- Symfony Console commands.AbstractModelQCommandloads the ModelQ instance from a PHP file path.
| Key | Type | Purpose |
|---|---|---|
task_queue |
List | Main FIFO queue |
task:{id} |
String | Task metadata JSON |
task_result:{id} |
String | Completed task result |
task_stream:{id} |
Stream | Streaming task output |
servers |
Hash | Registered worker servers |
processing_tasks |
Set | Currently processing task IDs |
delayed_tasks |
Sorted Set | Delayed tasks (score = exec time) |
- Producer calls
$modelq->enqueue('task_name', $data)→ Task pushed totask_queue - Worker pops from
task_queue→ moves task ID toprocessing_tasks - Handler executes (or yields for streaming → writes to
task_stream:{id}) - Result stored in
task_result:{id}→ task removed fromprocessing_tasks - Producer calls
$task->getResult()(polls) or$task->getStream()(xRead)
Task handlers that return Generator enable streaming. Output chunks are written to Redis Streams, allowing real-time consumption on the producer side via Task::getStream().
- Unit tests (
tests/Unit/): Test Task, Middleware, Exceptions in isolation - Integration tests (
tests/Integration/): Require Redis; test full ModelQ flow including worker spawning - Manual tests:
test_manual.php,test_worker.php,test_streaming.phpfor end-to-end verification