安装
本插件依赖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@','sssss');
QueueApi::smsSend("111111111",'1234');
QueueApi::smsNotice("111111111",'msg');
PS:队列中发短信和发邮件使用的是FastAdmin中自带的短信发送和邮件发送方法。因此可以兼容短信插件和后台配置邮件
大家可根据需求自行扩展,更多think-queue用法可参考/top-think/think-queue
可能遇到的问题
如果邮件发送遇到__autoload() is deprecated use spl_autoload_register() instead,有两种解决方案:找到application/common/library/Email.php第60行vendor('phpmailer.phpmailer.PHPMailerAutoload'); ,注释或删除它。
队列 开源 php 消息队列 - 基于think-queue消息队列 – 基于ThinkPHP和Bootstrap的极速后台开发框架...