swoft-cloud / swoft

🚀 PHP Microservice Full Coroutine Framework
https://swoft.org
Apache License 2.0
5.58k stars 786 forks source link

http client 使用co适配器出错 #182

Closed aprchen closed 6 years ago

aprchen commented 6 years ago
Q A
Bug report? yes/no
Feature request? yes/no
Swoft version 1.0.0
Swoole version 2.1.1 (by php --ri swoole)
PHP version 7.1.4 (by php -v)
Runtime environment Mac

swoole

swoole

swoole support => enabled
Version => 2.1.1
Author => tianfeng.han[email: mikan.tenny@gmail.com]
coroutine => enabled
kqueue => enabled
rwlock => enabled
async redis client => enabled
async http/websocket client => enabled
openssl => enabled
pcre => enabled
zlib => enabled
mysqlnd => enabled

Directive => Local Value => Master Value
swoole.aio_thread_num => 2 => 2
swoole.display_errors => On => On
swoole.use_namespace => On => On
swoole.use_shortname => On => On
swoole.fast_serialize => Off => Off
swoole.unixsock_buffer_size => 8388608 => 8388608

co 适配器测试


改为 co

$client = new Client([ 'adapter'=>'co' ]); $req = $client->get("http://www.baidu.com"); var_dump($req->getResponse()->getStatusCode());

结果出错: PHPUnit 7.0.3 by Sebastian Bergmann and contributors.

E 1 / 1 (100%)

Time: 657 ms, Memory: 14.00MB

There was 1 error:

1) Swoft\Test\Cases\WeChat\AccessTokenTest::testGetToken InvalidArgumentException: Invalid http client adapter

/Users/sl/Code/swoft/vendor/swoft/http-client/src/Client.php:250 /Users/sl/Code/swoft/vendor/swoft/http-client/src/Client.php:58 /Users/sl/Code/swoft/test/Cases/WeChat/AccessTokenTest.php:35

ERRORS! Tests: 1, Assertions: 0, Errors: 1

改为 swoole $client = new Client([ 'adapter'=>'swoole' ]); $req = $client->get("http://www.baidu.com"); var_dump($req->getResponse()->getStatusCode()); 结果: 2018/04/09 14:55:32 [DEBUG] [Application] Trigger the event applicationLoader PHPUnit 7.0.3 by Sebastian Bergmann and contributors.

[1] 27056 segmentation fault vendor/bin/phpunit test/Cases/WeChat/AccessTokenTest.php

改为 coroutine $client = new Client([ 'adapter'=>'coroutine' ]); $req = $client->get("http://www.baidu.com"); var_dump($req->getResponse()->getStatusCode());

结果与上面 swoole错误一样 2018/04/09 14:56:27 [DEBUG] [Application] Trigger the event applicationLoader PHPUnit 7.0.3 by Sebastian Bergmann and contributors.

[1] 27088 segmentation fault vendor/bin/phpunit test/Cases/WeChat/AccessTokenTest.php


> 测试代码,curl适配器运行正常
```php
$client = new Client([
            'adapter'=>'php'
        ]);
        $req = $client->get("http://www.baidu.com");
        var_dump($req->getResponse()->getStatusCode());
结果:
2018/04/09 14:52:38 [DEBUG] [Application] Trigger the event applicationLoader 
PHPUnit 7.0.3 by Sebastian Bergmann and contributors.

R                                                                   1 / 1 (100%)int(200)

Time: 762 ms, Memory: 14.00MB

There was 1 risky test:

1) Swoft\Test\Cases\WeChat\AccessTokenTest::testGetToken
This test did not perform any assertions

OK, but incomplete, skipped, or risky tests!
Tests: 1, Assertions: 0, Risky: 1.

这几个参数的由来是看的client 源码 image

huangzhhui commented 6 years ago

请更新 swoft/http-client 组件至 v1.0.2 以上以修复此问题