首页
下载
文档
社区
视频
捐赠
源代码
赞助商
AOT 编译器
AI 助理
商业产品
PHP AOT 原生编译器
Swoole-Compiler 代码加密器
CRMEB 新零售社交电商系统
登录
注册
全部
提问
分享
讨论
建议
公告
开发框架
CodeGalaxy
发表新帖
最近在做一个采集系统时,发现协程http客户端,在服务器完全断网,请求失败后不会立即退出
最近在做一个采集系统时,发现协程http客户端,在服务器完全断网(不是DNS失效,直接断网),请求失败后不会立即退出,这样导致进程还在占用部分资源,当我的服务器繁忙的时候,直接导致服务器内存耗干了。正常网络或者DNS失效这种情况是正常退出的 php 版本:7.2 ```php php --ri swoole swoole Swoole => enabled Author => Swoole Team <team@swoole.com> Version => 4.4.17 Built => Apr 4 2020 22:53:18 coroutine => enabled epoll => enabled eventfd => enabled signalfd => enabled cpu_affinity => enabled spinlock => enabled rwlock => enabled sockets => enabled openssl => OpenSSL 1.0.2k-fips 26 Jan 2017 http2 => enabled pcre => enabled zlib => 1.2.7 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 => On => On swoole.unixsock_buffer_size => 8388608 => 8388608 ``` 使用的是官方的例子 Co\run(function () { $client = new Swoole\Coroutine\Http\Client('127.0.0.1', 80); $client->setHeaders([ 'Host' => 'localhost', 'User-Agent' => 'Chrome/49.0.2587.3', 'Accept' => 'text/html,application/xhtml+xml,application/xml', 'Accept-Encoding' => 'gzip', ]); $client->get('/index.php'); echo $client->body; $client->close(); });  图片二中 已经答应完成了 但是还是没有结束 大概要等待 35s左右的时间 才会结束
发布于6年前 · 0 次浏览 · 来自
提问
冷暖自知25436
最近在做一个采集系统时,发现协程http客户端,在服务器完全断网(不是DNS失效,直接断网),请求失败后不会立即退出,这样导致进程还在占用部分资源,当我的服务器繁忙的时候,直接导致服务器内存耗干了。正常网络或者DNS失效这种情况是正常退出的 php 版本:7.2 ```php php --ri swoole swoole Swoole => enabled Author => Swoole Team <team@swoole.com> Version => 4.4.17 Built => Apr 4 2020 22:53:18 coroutine => enabled epoll => enabled eventfd => enabled signalfd => enabled cpu_affinity => enabled spinlock => enabled rwlock => enabled sockets => enabled openssl => OpenSSL 1.0.2k-fips 26 Jan 2017 http2 => enabled pcre => enabled zlib => 1.2.7 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 => On => On swoole.unixsock_buffer_size => 8388608 => 8388608 ``` 使用的是官方的例子 Co\run(function () { $client = new Swoole\Coroutine\Http\Client('127.0.0.1', 80); $client->setHeaders([ 'Host' => 'localhost', 'User-Agent' => 'Chrome/49.0.2587.3', 'Accept' => 'text/html,application/xhtml+xml,application/xml', 'Accept-Encoding' => 'gzip', ]); $client->get('/index.php'); echo $client->body; $client->close(); });  图片二中 已经答应完成了 但是还是没有结束 大概要等待 35s左右的时间 才会结束
赞
0
收藏
提问
分享
讨论
建议
公告
开发框架
CodeGalaxy
登录
后参与评论
评论
2020-04-05
鲁飞
请按模板提问,贴出 `php --ri swoole` 所打印的内容
赞
0
回复
2020-04-05
kis龍
回复
鲁飞
你好, 这里可以置顶吗? 把提问说明置顶下?
赞
0
回复
2020-04-05
冷暖自知25436
回复
鲁飞
```php [root@root azhuang]# php --ri swoole swoole Swoole => enabled Author => Swoole Team <team@swoole.com> Version => 4.4.17 Built => Apr 4 2020 22:53:18 coroutine => enabled epoll => enabled eventfd => enabled signalfd => enabled cpu_affinity => enabled spinlock => enabled rwlock => enabled sockets => enabled openssl => OpenSSL 1.0.2k-fips 26 Jan 2017 http2 => enabled pcre => enabled zlib => 1.2.7 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 => On => On swoole.unixsock_buffer_size => 8388608 => 8388608 ```
赞
0
回复
2020-04-06
鲁飞
回复
kis龍
提问的时候可以看到模板~
赞
0
回复
2020-04-06
鲁飞
回复
冷暖自知25436
我关掉wifi执行也是直接退出的 ``` $ time php test.php string(0) "" int(-1) php test.php 0.03s user 0.02s system 95% cpu 0.062 total # lufei @ lufeideMacBook-Pro in ~/Github [17:35:07] $ cat test.php <?php Co\run(function () { $client = new Swoole\Coroutine\Http\Client('www.baidu.com', 443, true); $client->setHeaders([ 'Host' => 'www.baidu.com', 'User-Agent' => 'Chrome/49.0.2587.3', 'Accept' => 'text/html,application/xhtml+xml,application/xml', 'Accept-Encoding' => 'gzip', ]); $client->set(['timeout'=>3]); $client->get('/'); var_dump($client->body); var_dump($client->statusCode); $client->close(); }); ```
赞
0
回复
2020-04-06
冷暖自知25436
回复
鲁飞
这边你实验没问题的话 我以为是我环境问题 我重新拉了一个docker 镜像来跑 还是存在相同的问题 难道和我系统有关 centos7
赞
0
回复
2020-04-06
冷暖自知25436

赞
0
回复
2020-04-09
sampson
请问问题解决了吗? 我也存在相同的问题
赞
0
回复