kislayphp/queue
Composer 安装命令:
pie install kislayphp/queue
包简介
Native PHP distributed job queue with a standalone queue server, producer client, worker runtime, retries, and DLQ support
关键字:
README 文档
README
Native PHP distributed job queue for long-running services. Phase 1 ships a standalone queue server, producer client, worker client, retries, delayed jobs, and DLQ support.
Part of the KislayPHP ecosystem.
What It Is
kislayphp/queue now has two modes:
Kislay\Queue\Serverfor the standalone queue nodeKislay\Queue\Clientfor producers and operational readsKislay\Queue\Workerfor consumersKislay\Queue\Jobfor ack/nack control inside a handlerKislay\Queue\Queueas the legacy local in-process queue for development fallback
Delivery model in 0.0.4:
- at-least-once delivery
- one leased job per worker fetch
- retries with backoff
- delayed jobs
- dead-letter queue support
- in-memory server state only
Install
pie install kislayphp/queue:0.0.4
Enable in php.ini:
extension=kislayphp_queue.so
5-Minute Quickstart
1. Start the queue server
<?php $server = new Kislay\Queue\Server(); $server->declare('emails', [ 'visibility_timeout_ms' => 30000, 'max_attempts' => 5, 'retry_backoff_ms' => 1000, 'dead_letter_queue' => 'emails.dlq', ]); $server->listen('0.0.0.0', 9020); $server->run();
2. Push a job
<?php $client = new Kislay\Queue\Client('http://127.0.0.1:9020'); $jobId = $client->push('emails', [ 'to' => 'user@example.com', 'subject' => 'Welcome', ], [ 'headers' => ['trace_id' => 'trace-1'], 'max_attempts' => 5, ]); var_dump($jobId);
3. Run a worker
<?php $worker = new Kislay\Queue\Worker('http://127.0.0.1:9020'); $worker->consume('emails', function (Kislay\Queue\Job $job) { $payload = $job->payload(); $headers = $job->headers(); sendEmail($payload['to'], $payload['subject']); return true; }, [ 'worker_id' => 'emails-worker-1', 'lease_ms' => 30000, ]);
Architecture
+------------------+ push +----------------------+
| Producer Service | ------------------> | Kislay\Queue\Server |
| Client | | owns queue state |
+------------------+ | leases jobs |
| retries / DLQ |
+------------------+ fetch +----------+-----------+
| Worker Service | <------------------------------+
| Kislay\Queue\Worker | ack / nack |
+------------------+ |
v
+------------------+
| queue.dlq |
+------------------+
Public API
namespace Kislay\Queue; class Server { public function __construct(array $options = []); public function listen(string $host, int $port): bool; public function run(): void; public function stop(): bool; public function declare(string $queue, ?array $options = null): bool; public function stats(?string $queue = null): array; } class Client { public function __construct(string $baseUrl, array $options = []); public function push(string $queue, mixed $payload, ?array $options = null): string; public function pushBatch(string $queue, array $jobs): array; public function stats(string $queue): array; public function purge(string $queue): int; } class Worker { public function __construct(string $baseUrl, array $options = []); public function consume(string $queue, callable $handler, ?array $options = null): bool; public function stop(): bool; } class Job { public function id(): string; public function queue(): string; public function payload(): mixed; public function headers(): array; public function attempts(): int; public function maxAttempts(): int; public function availableAt(): int; public function ack(): bool; public function nack(?bool $requeue = true, ?int $delayMs = null): bool; public function release(?int $delayMs = null): bool; }
Legacy local queue API remains available:
$queue = new Kislay\Queue\Queue(); $queue->enqueue('jobs', ['task' => 'send_email']); $job = $queue->dequeue('jobs');
Queue Semantics
0.0.4 semantics are intentionally explicit:
push()creates a job inreadyordelayedWorker::consume()fetches one leased job at a time- if the handler returns
true, the worker acks the job - if the handler returns
false, the worker nacks the job - if a handler throws, the worker nacks the job and stops with the exception still raised
- if retries are exhausted, the job moves to the configured DLQ
Operational Notes
What 0.0.4 is good for:
- background task processing between services
- queue semantics for microservice workloads
- development and early production validation
- explicit retry / DLQ flows
What 0.0.4 does not do yet:
- durable persistence across queue server restarts
- worker concurrency inside one
consume()loop - distributed replication
- exactly-once delivery
If the queue server process stops, in-memory jobs are lost. That is the correct tradeoff for this phase; do not market it as durable yet.
End-to-End Example
See example.php for a minimal runnable server / producer / worker flow.
Ecosystem Fit
Use this module for job queue semantics.
Use eventbus for fanout and realtime pub/sub.
Typical flow:
HTTP request -> queue push -> worker processes job -> eventbus emits completion event
Docs
- Full docs: https://skelves.com/kislayphp/docs/queue
- Insight articles: https://skelves.com/insights
License
kislayphp/queue 适用场景与选型建议
kislayphp/queue 是一款 基于 Shell 开发的 Composer 扩展包,目前已累计 8 次下载、GitHub Stars 达 0, 最近一次更新时间为 2026 年 02 月 15 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「php」 「microservices」 「php-extension」 「delayed-jobs」 「dead-letter-queue」 「cpp-extension」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 kislayphp/queue 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 kislayphp/queue 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 kislayphp/queue 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
The Listener component of the RabbitEvents library.
The Publisher component of the RabbitEvents package.
Laravel common
Laravel support for additional blueprint methods
Laravel comment system
Laravel support for GELF logging
统计信息
- 总下载量: 8
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 38
- 依赖项目数: 0
- 推荐数: 7
其他信息
- 授权协议: Apache-2.0
- 更新时间: 2026-02-15