php curl couldn't resolve host,cUrl模拟请求数据报错Couldn\'t resolve host xxxx

$url = 'http://www.baidu.com';

$options = array(

CURLOPT_CONNECTTIMEOUT => 30,

CURLOPT_RETURNTRANSFER => true,

CURLOPT_ENCODING => '',

CURLOPT_HEADER => 'true'

);

$params = $this->makeSign($requestBody);

Default_Service_Common::logErrorByFiles('xxx params =' . var_export($params, true), 'logs.log');

if (strtoupper($requestType) == 'GET') {

$url = $this->serverUrl . '?' . http_build_query($params);

} else {

$options[CURLOPT_POSTFIELDS] = $params;

$url = $this->serverUrl;

}

$options[CURLOPT_URL] = $url;

//initialise a CURL session

$connection = curl_init();

curl_setopt_array($connection, $options);

$response = curl_exec($connection);

$error = curl_errno($connection);

$error_message = curl_error($connection);

$httpStatus = curl_getinfo($connection, CURLINFO_HTTP_CODE);

$headerSize = curl_getinfo($connection, CURLINFO_HEADER_SIZE);

//close the connection

curl_close($connection);

$str = var_export(array($error_message, $httpStatus, $headerSize, $response), true);

Default_Service_Common::logErrorByFiles('xxx-> response:'.$str, 'logs.log');

日志报错 :

Couldn\'t resolve host xxxx

查询得知需要禁用ipv 6 模块

lsmod |grep ipv6; #/存在则已经开启了ipv6、无数据就说明禁用了

或者

ifconfig 命令查看信息是否有 "inet6 addr : ...."信息  、有则也说明开启了ipv6

ipv6关闭方法

在/etc/modprobe.d/dist.conf结尾添加

alias net-pf-10 off

alias ipv6 off

保存、重启服务器、 问题解决

查看系统发行版本命令

cat  /etc/issue

cat /proc/version

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值