php curl dnscache 问题

通过IP直接访问网站,如果是HTTP请求,使用ip地址直接访问接口,配合header中Host字段带上原来的域名信息即可;如果是https请求,curl 中有一个 -resolve 方法可以实现使用指定ip访问https网站.
但是发现连接的ip会有错乱。如下:

$resolve= array(sprintf(
“%s:%d:%s”,
“xx.xx.com”,
443,
“10.176.137.232”
));

结果1:

[0]=>
string(51) “* Added xx.xx..com:443:10.176.137.232 to DNS cache”
[1]=>
string(45) “* Hostname xx.xx.com was found in DNS cache”
[2]=>
string(27) “* Trying 10.228.10.176…”
[3]=>
string(56) “* Connected to xx.xx.com (10.228.10.176) port 443 (#0)”

结果2:
[0]=>
string(51) “* Added xx.xx.com:443:10.176.137.232 to DNS cache”
[1]=>
string(45) “* Hostname xx.xx.com was found in DNS cache”
[2]=>
string(28) “* Trying 10.176.137.232…”
[3]=>
string(57) “* Connected to xx.xx.com (10.176.137.232) port 443 (#0)”

通过测试发现 加上选项:

curl_setopt($ch, CURLOPT_DNS_USE_GLOBAL_CACHE,false); 就可解决。

js 格式转换

 

function userDate(uData){
	var myDate = new Date(uData*1000);
	var year = myDate.getFullYear();
	var month = myDate.getMonth() + 1;
	var day = myDate.getDate();
	return year + '-' + month + '-' + day;
}
var _d=userDate(1485014400);
console.log(_d);