简体   繁体   English

为 Guzzle 使用基于 Swoole \\Swoole\\Coroutine\\Http\\Client 的 HttpClientAdapter - 如何?

[英]Using a Swoole \Swoole\Coroutine\Http\Client based HttpClientAdapter for Guzzle - How?

I have tried to implement a Guzzle HandlerStack HttpClientAdapter for Swoole and use it via:我试图实现一个狂饮HandlerStack HttpClientAdapter为Swoole并通过使用它:

$handler = new \App\Swoole\HttpClientAdapter();
$client = new \GuzzleHttp\Client([
   'handler' => \GuzzleHttp\HandlerStack::create($handler),
]);
$res = $client->request('POST', 'http://localhost/foo');

The handler class looks like this:处理程序类如下所示:

namespace App\Swoole;

class HttpClientAdapter
{

    public function __invoke(RequestInterface $request, array $options)
    {
        // [..] init and request modification, path/port extraction removed

        $cli = new \Swoole\Coroutine\Http\Client($ip, $port, $ssl);
        $cli->execute($path);
        $cli->close();

        return new Promise\FulfilledPromise(

            new Psr7\Response($cli->statusCode, $cli->headers, $cli->body)
        );
    }
}

This actually works - but only if i put in a MockServer Proxy in between.这实际上有效 - 但前提是我在两者之间放置了一个MockServer 代理 Without, i just do not get any data back ... i have tried using different endpoints, but to no avail.没有,我只是没有取回任何数据......我尝试使用不同的端点,但无济于事。 Does anybody know how to tackle/debug the problem and/or is there a Swoole Guzzle Adapter out there in the wild?有没有人知道如何解决/调试问题和/或在野外是否有 Swoole Guzzle Adapter?

Well, this work is awesome.嗯,这个作品很棒。 But I suggest another httpclient based on swoole coroutine: https://github.com/swlib/saber/blob/master/README-EN.md但我建议另一个基于 swoole 协程的 httpclient: https : //github.com/swlib/saber/blob/master/README-EN.md

It's developed by swoole core developer and you will find it quite look like Guzzle.它是由 swoole 核心开发人员开发的,你会发现它看起来很像 Guzzle。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM