队列 开源 php,消息队列 - 基于think-queue消息队列 – 基于ThinkPHP和Bootstrap的极速后台开发框架...
安装本插件依赖thinkphp官方提供的think-queue队列,安装:composer require topthink/think-queue安装后在application/extra下将产生一个queue.php配置文件:['connector'=>'sync' //驱动类型,可选择 sync(默认):同步执行,database:数据库驱动,redis:Redis驱动,topthin
安装
本插件依赖thinkphp官方提供的think-queue队列,安装:composer require topthink/think-queue
安装后在application/extra下将产生一个queue.php配置文件:[
'connector'=>'sync' //驱动类型,可选择 sync(默认):同步执行,database:数据库驱动,redis:Redis驱动,topthink:Topthink驱动
//或其他自定义的完整的类名
]
推荐使用redis驱动,参考配置如下:return [
//'connector' => 'Sync',
//redis
'connector'=>'redis',
'expire' => 0,
'default' => 'default',
'host' => '127.0.0.1',
'port' => 6379,
'password' => '',
'select' => 0,
'timeout' => 0,
'persistent' => false
//database
// 'connector' => 'database',
// 'expire' => 60,
// 'default' => 'default',
// 'table' => 'faqueue_jobs',
// 'dsn' => [
// 'type' => 'mysql',
// 'database' => '',
// 'hostname' => '',
// 'username' => '',
// 'password' => '',
// 'prefix' => '',
// ]
];
使用
先启动队列,有两种方式:# 建议开发测试时使用
php think queue:listen
# 建议生产环境使用
php think queue:work --daemon(不加--daemon为执行单个任务)
本插件默认集成了异步邮件和短信发送功能,任务入队:QueueApi::sendEmail("测试队列",'xxxxxx@qq.com','sssss');
QueueApi::smsSend("111111111",'1234');
QueueApi::smsNotice("111111111",'msg');
PS:队列中发短信和发邮件使用的是FastAdmin中自带的短信发送和邮件发送方法。因此可以兼容短信插件和后台配置邮件
大家可根据需求自行扩展,更多think-queue用法可参考https://github.com/top-think/think-queue
可能遇到的问题
如果邮件发送遇到__autoload() is deprecated use spl_autoload_register() instead,有两种解决方案:找到application/common/library/Email.php第60行vendor('phpmailer.phpmailer.PHPMailerAutoload'); ,注释或删除它。

DAMO开发者矩阵,由阿里巴巴达摩院和中国互联网协会联合发起,致力于探讨最前沿的技术趋势与应用成果,搭建高质量的交流与分享平台,推动技术创新与产业应用链接,围绕“人工智能与新型计算”构建开放共享的开发者生态。
更多推荐
所有评论(0)