slm/queue-doctrine
最新稳定版本:4.4.0
Composer 安装命令:
composer require slm/queue-doctrine
包简介
Laminas Framework module that integrates Doctrine as queuing system
README 文档
README
Important notice
We decided to move onto Symfony Messenger and we are therefore not maintaining this repository anymore. Feel free to fork it and make it your own.
Created by Stefan Kleff
Requirements
Note: it's necessary require the doctrine package in composer.json file.
Installation
Run composer require slm/queue-doctrine.
If you have the laminas/laminas-component-installer package installed, it will ask you to enable the module (and SlmQueue), both in Laminas and Mezzio. Otherwise, add the module to the list:
- in Laminas MVC, enable the module by adding
SlmQueueDoctrinein your application.config.php file. - in Mezzio, enable the module by adding
SlmQueueDoctrine\ConfigProvider::class,in your config.php file.
Note: Don't forget install SlmQueue in you config file, which is required.
Documentation
Before reading SlmQueueDoctrine documentation, please read SlmQueue documentation.
Configuring the connection
You need to register a doctrine connection which SlmQueueDoctrine will use to access the database into the service manager. Here are some examples.
Connection parameters can be defined in the application configuration:
<?php return [ 'doctrine' => [ 'connection' => [ // default connection name 'orm_default' => [ 'driverClass' => 'Doctrine\DBAL\Driver\PDOMySql\Driver', 'params' => [ 'host' => 'localhost', 'port' => '3306', 'user' => 'username', 'password' => 'password', 'dbname' => 'database', ] ] ] ], ];
Creating the table from SQL file
You must create the required table that will contain the queue's you may use the schema located in 'data/queue_default.sql'. If you change the table name look at Configuring queues
>mysql database < data/queue_default.sql Creating the table from Doctrine Entity
There is an alternative way to create 'queue_default' table in your database by copying Doctrine Entity 'date/DefaultQueue.php' to your entity folder ('Application\Entity' in our example) and executing Doctrine's 'orm:schema-tool:update' command which should create the table for you. Notice that DefaultQueue entity is only used for table creation and is not used by this module internally.
Adding queues
return [ 'slm_queue' => [ 'queue_manager' => [ 'factories' => [ 'foo' => 'SlmQueueDoctrine\Factory\DoctrineQueueFactory' ] ] ] ];
Adding jobs
return [ 'slm_queue' => [ 'job_manager' => [ 'factories' => [ 'My\Job' => 'My\JobFactory' ] ] ] ];
Configuring queues
The following options can be set per queue ;
- connection (defaults to 'doctrine.connection.orm_default') : Name of the registered doctrine connection service
- table_name (defaults to 'queue_default') : Table name which should be used to store jobs
- deleted_lifetime (defaults to 0) : How long to keep deleted (successful) jobs (in minutes)
- buried_lifetime (defaults to 0) : How long to keep buried (failed) jobs (in minutes)
return [ 'slm_queue' => [ 'queues' => [ 'foo' => [ // ... ] ] ] ];
Provided Worker Strategies
In addition to the provided strategies by SlmQueue SlmQueueDoctrine comes with these strategies;
ClearObjectManagerStrategy
This strategy will clear the ObjectManager before execution of individual jobs. The job must implement the DoctrineModule\Persistence\ObjectManagerAwareInterface or SlmQueueDoctrine\Persistence\ObjectManagerAwareInterface.
listens to:
process.jobevent at priority 1000
options:
- none
This strategy is enabled by default.
IdleNapStrategy
When no jobs are available in the queue this strategy will make the worker wait for a specific amount time before quering the database again.
listens to:
process.idleevent at priority 1
options:
nap_durationdefaults to 1 (second)
This strategy is enabled by default.
Operations on queues
push
Valid options are:
- scheduled: the time when the job will be scheduled to run next
- numeric string or integer - interpreted as a timestamp
- string parserable by the DateTime object
- DateTime instance
- delay: the delay before a job become available to be popped (defaults to 0 - no delay -)
- numeric string or integer - interpreted as seconds
- string parserable (ISO 8601 duration) by DateTimeInterval::__construct
- string parserable (relative parts) by DateTimeInterval::createFromDateString
- DateTimeInterval instance
- priority: the lower the priority is, the sooner the job get popped from the queue (default to 1024)
Examples:
// scheduled for execution asap $queue->push($job); // will get executed before jobs that have higher priority $queue->push($job, [ 'priority' => 200, ]); // scheduled for execution 2015-01-01 00:00:00 (system timezone applies) $queue->push($job, [ 'scheduled' => 1420070400, ]); // scheduled for execution 2015-01-01 00:00:00 (system timezone applies) $queue->push($job, [ 'scheduled' => '2015-01-01 00:00:00' ]); // scheduled for execution at 2015-01-01 01:00:00 $queue->push($job, [ 'scheduled' => '2015-01-01 00:00:00', 'delay' => 3600 ]); // scheduled for execution at now + 300 seconds $queue->push($job, [ 'delay' => 'PT300S' ]); // scheduled for execution at now + 2 weeks (1209600 seconds) $queue->push($job, [ 'delay' => '2 weeks' ]); // scheduled for execution at now + 300 seconds $queue->push($job, [ 'delay' => new DateInterval("PT300S")) ]);
Worker actions
Interact with workers from the command line from within the public folder of your Laminas Framework 2 application
Starting a worker
Start a worker that will keep monitoring a specific queue for jobs scheduled to be processed. This worker will continue until it has reached certain criteria (exceeds a memory limit or has processed a specified number of jobs).
vendor/bin/laminas slm-queue:start <queueName>
A worker will exit when you press cntr-C after it has finished the current job it is working on. (PHP doesn't support signal handling on Windows)
Recovering jobs
To recover jobs which are in the 'running' state for prolonged period of time (specified in minutes) use the following command.
vendor/bin/laminas slm-queue:doctrine:recover <queueName> [--executionTime=]
Note : Workers that are processing a job that is being recovered are NOT stopped.
slm/queue-doctrine 适用场景与选型建议
slm/queue-doctrine 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 323.02k 次下载、GitHub Stars 达 31, 最近一次更新时间为 2026 年 01 月 04 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「database」 「queue」 「db」 「doctrine」 「job」 「laminas」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 slm/queue-doctrine 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 slm/queue-doctrine 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 slm/queue-doctrine 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Dibi is Database Abstraction Library for PHP
Store your language lines in the database, yaml or other sources
PHP AMQP Binding Library
A Laravel package to monitor queue jobs.
A package for automatically encrypting and decrypting Eloquent attributes in Laravel 5.5+, based on configuration settings.
A PSR-7 compatible library for making CRUD API endpoints
统计信息
- 总下载量: 323.02k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 31
- 点击次数: 21
- 依赖项目数: 5
- 推荐数: 2
其他信息
- 授权协议: BSD-3-Clause
- 更新时间: 2026-01-04