测试代码:
$ch = curl\_init('www.google.com');
curl\_setopt($ch, CURLOPT\_IPRESOLVE, CURL\_IPRESOLVE\_V4);
curl\_setopt($ch, CURLOPT\_RETURNTRANSFER, false);
curl\_setopt($ch, CURLOPT\_HEADER, true);
curl\_exec($ch);
通过 php 交互模式,可以解析域名,并下载到正确的 html。但是在 php 网页程序中执行,就返回错误
string(65) "Could not resolve host: www.google.com; Name or service not known"
服务器环境:CentOS 7.7 php 7.3 Apache/2.4.6
解析服务器:1.1.1.1和8.8.8.8
ping www.google.com 结果正常。
注意:我开启了防火墙和SELINUX,开放的端口只有 HTTP/HTTPS/SSH,我认为关闭防火墙和SELINUX是一种愚蠢的行为,不要让我关闭SELINUX。
加上 http://