From cf1703c94f1a3ee026dd48f4c8e13c355d66e1ac Mon Sep 17 00:00:00 2001 From: lanhai Date: Thu, 9 Apr 2026 18:12:05 +0800 Subject: [PATCH] =?UTF-8?q?=E2=9A=A1=20perf(appstore):=20=E5=BC=BA?= =?UTF-8?q?=E5=88=B6=E4=BD=BF=E7=94=A8=20CoroutineHandler=20=E4=BF=AE?= =?UTF-8?q?=E5=A4=8D=20HTTP=20=E5=AE=A2=E6=88=B7=E7=AB=AF=E6=80=A7?= =?UTF-8?q?=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Service/Impl/AppStoreServiceImpl.php | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/Service/Impl/AppStoreServiceImpl.php b/src/Service/Impl/AppStoreServiceImpl.php index 2909366..917f519 100644 --- a/src/Service/Impl/AppStoreServiceImpl.php +++ b/src/Service/Impl/AppStoreServiceImpl.php @@ -14,10 +14,12 @@ use GuzzleHttp\Client; use GuzzleHttp\Exception\GuzzleException; +use GuzzleHttp\HandlerStack; use Hyperf\Collection\Arr; use Hyperf\Collection\Collection; use Hyperf\Contract\ConfigInterface; use Hyperf\Guzzle\ClientFactory; +use Hyperf\Guzzle\CoroutineHandler; use Mine\AppStore\Plugin; use Mine\AppStore\Service\AppStoreService; @@ -34,9 +36,21 @@ public function __construct( ClientFactory $clientFactory, ConfigInterface $config ) { + /** + * 修复一:强制使用 CoroutineHandler + * + * 问题根源:bin/hyperf.php 中定义了 SWOOLE_HOOK_ALL(包含 SWOOLE_HOOK_NATIVE_CURL), + * Hyperf 的 ClientFactory 检测到该 flag 后,认为 cURL 已被 Swoole Hook 接管, + * 因此不会自动切换为 CoroutineHandler,而是退化使用 hooked cURL。 + * + * 修复方案:手动创建 HandlerStack 并指定 CoroutineHandler, + * 绕过 ClientFactory 的自动检测逻辑,直接使用 Swoole 原生非阻塞 HTTP 客户端, + */ + $stack = HandlerStack::create(new CoroutineHandler()); $this->client = $clientFactory->create([ 'base_uri' => 'https://www.mineadmin.com/server/server/', 'timeout' => 10.0, + 'handler' => $stack, ]); $this->config = $config->get('mine-extension'); }