search
尋找貓咪~QQ 地點 桃園市桃園區 Taoyuan , Taoyuan

別讓不工作的 IPv6 影響 PHP 的網路連線速度(DNS 解析錯誤) - Soul & Shell Blog

最近發生 PHP 呼叫其他 WebService 速度過慢的問題,在 Linux OS 使用 TCP Socket 進行 HTTP 連線速度正常,但是使用 PHP 呼叫 fsockopen() 或 file_get_contents() 就是特別慢。仔細測試後發現如果是使用 IP Address 進行連線速度就正常,使用 Domain 就特別慢,看來問題就是出在 DNS 解析!

後來發現 Linux 的 IPv6 是不工作的,一般來說裝好 Linux 我都會關閉 IPv6 的相關功能與設定,接著關閉 IPv6 之後 PHP 的連線速度也就正常了。以下是關閉 Linux IPv6 的方法:

Disable IPv6 Networking Support - 關閉 IPv6 網路支援

編輯 /etc/sysconfig/network 並加入以下設定
1
NETWORKING_IPV6=no

Disable IPv6 Protocol Stack for Kernel - 關閉 IPv6 相關 module

編輯 /etc/modprobe.conf 並加入以下設定

1
2
alias net-pf-10 off
alias ipv6 off

Disable IPv6 Firewall - 關閉 IPv6 iptables 防火牆支援

1
2
3
4
5
6
7
[root@server ~]$ /etc/init.d/ip6tables stop
Flushing firewall rules: [ OK ]
Setting chains to policy ACCEPT: filter [ OK ]
Unloading ip6tables modules: [ OK ]
Turn ipv6 firewall off during future usage:
 
[root@server ~]$ /sbin/chkconfig --level 35 ip6tables off

Issue with localhost - 註解所有 IPv6 Hosts

編輯 /etc/hosts 註解所有 IPv6 解析設定

1
#::1    localhost.localdomain   localhost

參考資料

平價童鞋首選



熱門推薦

本文由 toright 提供 原文連結

寵物協尋 相信 終究能找到回家的路
寫了7763篇文章,獲得2次喜歡
留言回覆
回覆
精彩推薦