webman,在使用webman/redis-queue + webman/think-orm 库的时候,会出现:plugin.webman.redis-queue.default.INFO: Error: Call to a member function getConfig() on null in /www/wwwroot/www.test.com/vendor/topthink/think-orm/src/db/Connection.php:171
场景:使用webman/redis-queue队列,然后在config/thinkorm 里面配置了多个数据库,在队列的消费方法里面去使用Db::connect('其他配置的数据库')的时候,会出现上面的错误,偶尔出现,重启webman之后,就好了,然后不知过多久,又会出现。
正常的模型使用又是可以的,模型用的是默认配置
//这样没问题
$userInfo = User::find(1);
//这样使用就会报错
Db::connect('site_1')->table('user')->where(['username' => 'test'])->find();
config/thinkorm.php
[
'default' => 'mysql',
'connections' => [
'mysql' => [
// 数据库类型
'type' => 'mysql',
// 服务器地址
'hostname' => env('DB_HOST'),
// 数据库名
'database' => env('DB_NAME'),
// 数据库用户名
'username' => env('DB_USER'),
// 数据库密码
'password' => env('DB_PASSWORD'),
// 数据库连接端口
'hostport' => env('DB_PORT'),
// 数据库连接参数
'params' => [
// 连接超时3秒
\PDO::ATTR_TIMEOUT => 3,
],
// 数据库编码默认采用utf8
'charset' => 'utf8mb4',
// 数据库表前缀
'prefix' => env('DB_PREFIX'),
// 断线重连
'break_reconnect' => true,
// 自定义分页类
'bootstrap' => ''
],
'site_1' => [
'type' => 'mysql',
'hostname' => '1.2.3.4',
'username' => 'test',
'database' => 'test',
'password' => '123123',
'hostport' => '3306',
'charset' => 'utf8mb4',
'params' => [
\PDO::ATTR_TIMEOUT => 10,
],
'break_reconnect' => true,
]
]
plugin.webman.redis-queue.default.INFO: Error: Call to a member function getConfig() on null in /www/wwwroot/www.test.com/vendor/topthink/think-orm/src/db/Connection.php:171
系统:CentOS 7
mysql版本:8.0
PHP版本:8.2
Redis版本:7.4
workerman/webman-framework: "~2.1"
webman/think-orm: "~2.1"
webman/redis-queue: "^2.1"
试一下用\support\think\Db::connect
目前来说,是这样用的
use support\think\Db
Db::connect()
composer require webman/redis-queue ^2.1.1
更新到最新版本
额,好的。