cURL error 1014: SSL verify failed 报错
阅读原文时间:2023年07月08日阅读:1

报错

[ERROR] cURL error 1014: SSL verify failed (see https://curl.haxx.se/libcurl/c/libcurl-errors.html) for https://mgobe.tencentcloudapi.com/[247] in /www/wwwroot/*.net/vendor/
[ERROR] #0 /www/wwwroot/tencentgame.net/vendor/tencentcloud/tencentcloud-sdk-php/src/TencentCloud/Common/AbstractClient.php(175): TencentCloud\Common\AbstractClient->doRequestWithOptions()
#1 /www/wwwroot/*.net/app/Controller/IndexController.php(46): TencentCloud\Common\AbstractClient->__call()
#2 /www/wwwroot/*.net/vendor/hyperf/http-server/src/CoreMiddleware.php(161): App\Controller\IndexController->index()
#3 /www/wwwroot/*.net/vendor/hyperf/http-server/src/CoreMiddleware.php(113): Hyperf\HttpServer\CoreMiddleware->handleFound()

框架

hyperf swoole 4.5.9 openssl1.1.1

方向

1.系统层。swoole的 openssl版本太低。php --ri swoole 查看openssl版本为1.0.1.系统查看openssl version 版本为1.1.1 升级版本swoole的openssl版本。重新编译(行不通)

2.框架问题

hyperf框架swoole采用协程模式,guzzle会造成阻塞报错

根据 https://hyperf.wiki/2.1/#/zh-cn/guzzle

use GuzzleHttp\Client;
use Hyperf\Guzzle\CoroutineHandler;
use GuzzleHttp\HandlerStack;

$client = new Client([
    'base_uri' => 'http://127.0.0.1:8080',
    'handler' => HandlerStack::create(new CoroutineHandler()),
    'timeout' => 5,
    'swoole' => [
        'timeout' => 10,
        'socket_buffer_size' => 1024 * 1024 * 2,
    ],
]);

$response = $client->get('/');

1.在 请求处加入 handler => HandlerStack::create(new CoroutineHandler()) 解决问题

2.直接使用Hyperf\Guzzle\CoroutineHandler 作为处理器设置到 Guzzle 客户端内即可转为协程化运行,为了方便创建协程的 Guzzle 对象,我们提供了一个工厂类 Hyperf\Guzzle\ClientFactory 来便捷的创建客户端

<?php
use Hyperf\Guzzle\ClientFactory;

class Foo {
    /**
     * @var \Hyperf\Guzzle\ClientFactory
     */
    private $clientFactory;

    public function __construct(ClientFactory $clientFactory)
    {
        $this->clientFactory = $clientFactory;
    }

    public function bar()
    {
        // $options 等同于 GuzzleHttp\Client 构造函数的 $config 参数
        $options = [];
        // $client 为协程化的 GuzzleHttp\Client 对象
        $client = $this->clientFactory->create($options);
    }
}