Skip to content

如何快速释放 DB 连接 #2965

Answered by limingxinleo
limingxinleo asked this question in Q&A
Discussion options

You must be logged in to vote

显而易见,我们只需要让读取用户信息的逻辑,跑在子协程中,然后配合 Channel 阻塞当前协程即可。

v2.1 里已经实现了这个方法,v2.0 中我们可以导入以下组件

composer require gemini/waiter

然后我们可以调用 wait() 方法,达成这个效果。

// 读取用户信息
$user = wait(function() {
    return User::query()->find(1);
});

// 请求第三方接口
$client->request($user);

// 保存用户信息
$user->save();

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by limingxinleo
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
1 participant