linux下php使用curl导致大量TIME_WAIT求解决
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
网站运行一会儿就有大量TIME_WAIT,通过netstat可以看到是php调用curl导致的
目前CURLOPT_CONNECTTIMEOUT设置为:3
CURLOPT_TIMEOUT设置为:3
网上说修改/etc/sysctl.conf,
net.ipv4.tcp_syncookies = 1
net.ipv4.tcp_tw_reuse = 1
net.ipv4.tcp_tw_recycle = 1
net.ipv4.tcp_fin_timeout = 30
我修改报错
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'
服务器是centos
椿sama
10 years, 1 month ago
Answers
不懂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'
喵森あおい
answered 10 years ago