centos - linux下php使用curl导致大量TIME_WAIT求解决

WBOY
Release: 2016-06-06 20:41:06
Original
1694 people have browsed it

<code>netstat -an|awk '/tcp/ {print $6}'|sort|uniq -c
    173 ESTABLISHED
     43 FIN_WAIT1
     20 FIN_WAIT2
      5 LAST_ACK
      7 LISTEN
      2 SYN_RECV
      3 SYN_SENT
   1745 TIME_WAIT
</code>
Copy after login
Copy after login

网站运行一会儿就有大量TIME_WAIT,通过netstat可以看到是php调用curl导致的

目前CURLOPT_CONNECTTIMEOUT设置为:3
CURLOPT_TIMEOUT设置为:3

网上说修改/etc/sysctl.conf,

<code>net.ipv4.tcp_syncookies = 1
net.ipv4.tcp_tw_reuse = 1
net.ipv4.tcp_tw_recycle = 1
net.ipv4.tcp_fin_timeout = 30
</code>
Copy after login
Copy after login

我修改报错

<code>error: permission denied on key 'net.ipv4.tcp_tw_reuse'
error: permission denied on key 'net.ipv4.tcp_tw_recycle'
error: permission denied on key 'net.ipv4.tcp_fin_timeout'
</code>
Copy after login
Copy after login

服务器是centos

回复内容:

<code>netstat -an|awk '/tcp/ {print $6}'|sort|uniq -c
    173 ESTABLISHED
     43 FIN_WAIT1
     20 FIN_WAIT2
      5 LAST_ACK
      7 LISTEN
      2 SYN_RECV
      3 SYN_SENT
   1745 TIME_WAIT
</code>
Copy after login
Copy after login

网站运行一会儿就有大量TIME_WAIT,通过netstat可以看到是php调用curl导致的

目前CURLOPT_CONNECTTIMEOUT设置为:3
CURLOPT_TIMEOUT设置为:3

网上说修改/etc/sysctl.conf,

<code>net.ipv4.tcp_syncookies = 1
net.ipv4.tcp_tw_reuse = 1
net.ipv4.tcp_tw_recycle = 1
net.ipv4.tcp_fin_timeout = 30
</code>
Copy after login
Copy after login

我修改报错

<code>error: permission denied on key 'net.ipv4.tcp_tw_reuse'
error: permission denied on key 'net.ipv4.tcp_tw_recycle'
error: permission denied on key 'net.ipv4.tcp_fin_timeout'
</code>
Copy after login
Copy after login

服务器是centos

不懂PHP,仅仅针对你说的出现大量的TIME_WAIT来说,比较详细的解决方案见:http://huoding.com/2012/01/19/142

如果提示`error: permission denied on key 'net.ipv4.tcp_tw_reuse''.请'su'到root并临时关掉Selinux 'setenforce 0'

楼主,这个问题最终你是怎么解决的?我现在也遇到这种问题了。curl每次都关闭,大量请求的时候,还是出现大量的CLOSE_WAIT,ESTABLISHED,TIME_WAIT.请教下。

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template