ereborcodeforge/mithrilexecutor
Composer 安装命令:
composer require ereborcodeforge/mithrilexecutor
包简介
Lightweight PHP background job runner with filesystem queue, daemon mode, and pluggable resolvers (no dependencies).
README 文档
README
Simple, dependency-free PHP background job runner using filesystem queues.
🚀 Quick Start
1. Create a Task Class
Any PHP class can be a job. No interface required.
// src/Tasks/EmailTask.php namespace App\Tasks; class EmailTask { public function __construct(private string $apiKey) {} public function send(string $to, string $subject): void { // Send email logic... echo "Email sent to $to"; } }
2. Enqueue a Job (Programmatic)
Use this in your application (Controller, Service, etc) to dispatch jobs.
use MithrilExecutor\Queue\FileJobQueue; use MithrilExecutor\ValueObjects\Job; use App\Tasks\EmailTask; // Setup $queue = new FileJobQueue(__DIR__ . '/storage'); // Create Job $job = new Job( id: uniqid('job-'), className: EmailTask::class, constructorArgs: ['my-api-key'], // Passed to __construct calls: [ [ 'method' => 'send', 'args' => ['user@example.com', 'Welcome!'] // Passed to method ] ] ); // Dispatch $queue->enqueue($job);
3. Run the Worker (Terminal)
Start the supervisor to process jobs.
php bin/mithril daemon --bootstrap=example/bootstrap.php --concurrency=4 --memory=128M
🛠 CLI Reference & Flags
Global Flags (Available for most commands)
| Flag | Description |
|---|---|
--bootstrap |
Path to a PHP file that returns a ResolverInterface. Used to load your application's autoloader or DI container. Optional if your jobs are already autoloaded by Composer in the project root. |
--storage |
Custom path to the storage directory (defaults to storage/). |
daemon
Starts the worker loop (supervisor). Recommended for production.
| Flag | Default | Description | Example |
|---|---|---|---|
--concurrency |
1 |
Number of parallel worker processes to spawn. | --concurrency=5 |
--memory |
null |
Memory limit per process (passed to ini_set or PHP CLI). |
--memory=256M |
--sleep |
250 |
Sleep time (ms) when queue is empty to reduce CPU usage. | --sleep=1000 |
--bootstrap |
null |
Autoloader/Resolver file (see Global Flags). | --bootstrap=autoload.php |
Example:
# Runs 5 workers, each limited to 128MB RAM, loading classes from bootstrap.php
php bin/mithril daemon --concurrency=5 --memory=128M --bootstrap=src/bootstrap.php
list
Lists jobs in the queue.
| Flag | Options | Description | Example |
|---|---|---|---|
--status |
pending, running, done, failed |
Filter jobs by status. Default shows all. | --status=failed |
--format |
table (default), json, csv |
Output format. JSON/CSV are good for scripts. | --format=json |
--output |
null |
Write output to a file instead of the screen. | --output=report.csv |
Example:
# Export all failed jobs to a CSV file
php bin/mithril list --status=failed --format=csv --output=failed_jobs.csv
work
Processes a single job and exits. Useful for cron jobs or one-off tasks.
| Flag | Description |
|---|---|
--quiet |
Suppress "No job found" and "Running worker" logs. Useful for cron to avoid spamming emails. |
--memory |
Set memory limit for this specific run. |
Example:
php bin/mithril work --memory=512M --quiet --bootstrap=autoload.php
run
Executes a specific job file directly (bypassing the queue logic). Useful for debugging a failed job file manually.
| Flag | Description |
|---|---|
--file |
Required. Absolute path to the .json job file to execute. |
Example:
php bin/mithril run --file=/path/to/storage/queue/failed/job-123.json --bootstrap=autoload.php
enqueue
Enqueue a job via CLI (useful for testing).
| Flag | Description |
|---|---|
--class |
Full class name of the job. |
--ctor |
JSON array of arguments for the constructor. |
--calls |
JSON array of method calls: [{"method":"name","args":[...]}]. |
Example:
php bin/mithril enqueue \ --class="App\Tasks\EmailTask" \ --ctor='["api-key"]' \ --calls='[{"method":"send","args":["thales@example.com","Hello"]}]'
📂 Directory Structure
bin/mithril: The CLI executable.storage/queue: Where pending/running/done jobs are stored as JSON.src/: The library source code.example/: Demo files.
ereborcodeforge/mithrilexecutor 适用场景与选型建议
ereborcodeforge/mithrilexecutor 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 5 次下载、GitHub Stars 达 1, 最近一次更新时间为 2024 年 09 月 12 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「queue」 「php」 「filesystem」 「background」 「job」 「worker」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 ereborcodeforge/mithrilexecutor 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 ereborcodeforge/mithrilexecutor 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 ereborcodeforge/mithrilexecutor 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
A SDK for working with B2 cloud storage.
A PHP class providing static methods for reading, writing, copying, moving, and deleting files and directories, MIME type detection, image size detection, and file permission management
PHP AMQP Binding Library
A Laravel package to monitor queue jobs.
The flysystem adapter for yandex disk rest api.
A sleek PHP wrapper around rclone with Laravel-style fluent API syntax
统计信息
- 总下载量: 5
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 14
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2024-09-12