首页
下载
文档
社区
视频
捐赠
源代码
赞助商
AOT 编译器
AI 助理
商业产品
PHP AOT 原生编译器
Swoole-Compiler 代码加密器
CRMEB 新零售社交电商系统
登录
注册
全部
提问
分享
讨论
建议
公告
开发框架
CodeGalaxy
发表新帖
协程http客户端报8004错误
### 问题描述 使用hyperf/guzzle进行请求谷歌接口(使用了代理)。请求开始后一段时间,开始出现 8004错误,也有部分110错误。 ### Swoole版本,PHP版本,以及操作系统版本信息 ``` php PHP 7.2.34 (cli) (built: Oct 22 2020 10:22:35) ( NTS ) Copyright (c) 1997-2018 The PHP Group Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies with Zend OPcache v7.2.34, Copyright (c) 1999-2018, by Zend Technologies ``` ``` swoole Swoole => enabled Author => Swoole Team <team@swoole.com> Version => 4.5.5 Built => Oct 26 2020 16:00:26 coroutine => enabled epoll => enabled eventfd => enabled signalfd => enabled cpu_affinity => enabled spinlock => enabled rwlock => enabled sockets => enabled openssl => OpenSSL 1.0.2n 7 Dec 2017 http2 => enabled pcre => enabled zlib => 1.2.3 mutex_timedlock => enabled pthread_barrier => enabled futex => enabled mysqlnd => enabled async_redis => enabled Directive => Local Value => Master Value swoole.enable_coroutine => On => On swoole.enable_library => On => On swoole.enable_preemptive_scheduler => Off => Off swoole.display_errors => On => On swoole.use_shortname => Off => Off swoole.unixsock_buffer_size => 8388608 => 8388608 ``` ### 相关代码 ```php <?php // 伪代码 use Hyperf\Utils\Parallel; use Hyperf\Guzzle\ClientFactory; /** @var ClientFactory $clientFactory */ $clientFactory = null; $client = $clientFactory->create([ 'base_uri' => 'https://fcm.googleapis.com/v1/projects/abcedfg/messages:send', 'timeout' => 5, 'proxy' => 'tcp://111.222.111.222:1111' ]); $targets = []; // 数组很大 100000+ $parallel = new Parallel(); foreach($targets as $target) { $parallel->add(function () use ($client){ try { $client->post('', [ 'body' => json_encode(['xxx']), 'headers' => [ 'Authorization' => 'Bearer abc...efg', 'Content-Type' => 'application/json', ], ]); } catch (\GuzzleHttp\Exception\ClientException $e) { } catch (\GuzzleHttp\Exception\BadResponseException $e) { } catch (\GuzzleHttp\Exception\TransferException $e) { echo $e->getMessage() . PHP_EOL; } }); } $parallel->wait(); ``` ### 你期待的结果是什么?实际看到的错误信息又是什么? 怎么避免8004错误。
发布于5年前 · 3 次浏览 · 来自
提问
包
### 问题描述 使用hyperf/guzzle进行请求谷歌接口(使用了代理)。请求开始后一段时间,开始出现 8004错误,也有部分110错误。 ### Swoole版本,PHP版本,以及操作系统版本信息 ``` php PHP 7.2.34 (cli) (built: Oct 22 2020 10:22:35) ( NTS ) Copyright (c) 1997-2018 The PHP Group Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies with Zend OPcache v7.2.34, Copyright (c) 1999-2018, by Zend Technologies ``` ``` swoole Swoole => enabled Author => Swoole Team <team@swoole.com> Version => 4.5.5 Built => Oct 26 2020 16:00:26 coroutine => enabled epoll => enabled eventfd => enabled signalfd => enabled cpu_affinity => enabled spinlock => enabled rwlock => enabled sockets => enabled openssl => OpenSSL 1.0.2n 7 Dec 2017 http2 => enabled pcre => enabled zlib => 1.2.3 mutex_timedlock => enabled pthread_barrier => enabled futex => enabled mysqlnd => enabled async_redis => enabled Directive => Local Value => Master Value swoole.enable_coroutine => On => On swoole.enable_library => On => On swoole.enable_preemptive_scheduler => Off => Off swoole.display_errors => On => On swoole.use_shortname => Off => Off swoole.unixsock_buffer_size => 8388608 => 8388608 ``` ### 相关代码 ```php <?php // 伪代码 use Hyperf\Utils\Parallel; use Hyperf\Guzzle\ClientFactory; /** @var ClientFactory $clientFactory */ $clientFactory = null; $client = $clientFactory->create([ 'base_uri' => 'https://fcm.googleapis.com/v1/projects/abcedfg/messages:send', 'timeout' => 5, 'proxy' => 'tcp://111.222.111.222:1111' ]); $targets = []; // 数组很大 100000+ $parallel = new Parallel(); foreach($targets as $target) { $parallel->add(function () use ($client){ try { $client->post('', [ 'body' => json_encode(['xxx']), 'headers' => [ 'Authorization' => 'Bearer abc...efg', 'Content-Type' => 'application/json', ], ]); } catch (\GuzzleHttp\Exception\ClientException $e) { } catch (\GuzzleHttp\Exception\BadResponseException $e) { } catch (\GuzzleHttp\Exception\TransferException $e) { echo $e->getMessage() . PHP_EOL; } }); } $parallel->wait(); ``` ### 你期待的结果是什么?实际看到的错误信息又是什么? 怎么避免8004错误。
赞
0
收藏
提问
分享
讨论
建议
公告
开发框架
CodeGalaxy
登录
后参与评论
评论
2020-11-12
李铭昕
有可能是连接数太多了。。 这么设置一下 ``` new Parallel(10); ```
赞
1
回复
2020-11-13
包
回复
李铭昕
有效果。8004消失了。
赞
0
回复
2020-11-12
鲁飞
错误信息贴出来
赞
0
回复
2020-11-12
包
抛的异常来自 Hyperf\Guzzle\CoroutineHandler 下面的checkStatusCode方法 具体错误信息就是: Connection failed, errCode=8004 Connection failed, errCode=110 Request timed out, errCode=110
赞
0
回复
2020-11-12
鲁飞
回复
包
用原生Swoole的协程Client试下
赞
0
回复
2020-11-12
包
回复
鲁飞
我想先问下8004是啥子报错?
赞
0
回复
2020-12-07
包
``` 2020-12-06 19:32:11 wrong http_proxy response received, [Request]: CONNECT fcm.googleapis.com:443 HTTP/1.1 Host: fcm.googleapis.com:443 User-Agent: Swoole/4.5.5 Proxy-Connection: Keep-Alive [Response]: HTTP/1.0 500 Internal Server Error Server: squid/3.1.23 Mime-Version: 1.0 Date: Sun, 06 Dec 2020 11:32:11 GMT Content-Type: text/html Content-Length: 3244 X-Squid-Error: ERR_SOCKET_FAILURE 98^M Vary: Accept-Language Content-Language: en ``` 8004的错误内容 我打印出来了。 应该是代理的问题。
赞
0
回复