DownloadAGENT_INSTRUCTIONS.md
Welcome, AI Agent! This document reflects the refactored minimal API of TaskPHP.
Project Overview
TaskPHP (Nahid\TaskPHP) is a high-performance concurrency library for PHP 7.4+. It uses child processes (proc_open) and IPC over pipes.
The Minimal API
The library has been refactored to prioritize the async/await pattern. Legacy methods like defer, concurrent, and background have been removed.
Core Chain
-
Configure: `Task::limit(int)`, `Task::timeout(int)`, `Task::bootstrap(mixed)`, `Task::failFast(bool)`, `Task::outputLimit(int)`.
-
Execute: `->async(array $tasks)` -> returns a `TaskGroup`.
-
Resolve:
- `->await(?callable $callback)`: Blocks until done. Optional callback to process results.
- `->forget()`: Detaches the process to run in the background.
Example
$results = Task::limit(5)
->async(['key' => fn() => 'data'])
->await();
Technical Context
-
Worker: `src/bin/worker.php` handles execution.
-
Bootstrapping: `bootstrap()` method replaces both path-based and object-based setters. It accepts a string path or a `TaskBootstrapInterface` object.
-
Process Management: `ProcessManager` handles the lifecycle. It supports concurrency limits and timeouts.
Development Rules
-
Internal Methods: Use `dispatch` logic inside `Task::async()`.
-
No Side Effects: Do not use `echo` in workers; it corrupts data.
-
PHP Compatibility: Maintain support for PHP 7.4. Use docblocks instead of union types in class properties if possible for broad compatibility.
|