Commit b46f700b authored by 杨培's avatar 杨培

支持 remoteIp 定义远程 IP 地址省去解析过程

parent 907869c5
...@@ -25,6 +25,7 @@ class Client ...@@ -25,6 +25,7 @@ class Client
protected $clientId; protected $clientId;
protected $clientSecret; protected $clientSecret;
protected $apiUrl; protected $apiUrl;
protected $remoteIp;
protected static $instance = []; protected static $instance = [];
protected static $config = []; protected static $config = [];
...@@ -145,6 +146,14 @@ class Client ...@@ -145,6 +146,14 @@ class Client
} }
protected function request($url, $post='', $headers=[]) { protected function request($url, $post='', $headers=[]) {
//如果设置了远程IP,则直接用IP连接,省去解析
if ($this->remoteIp) {
$host = parse_url($url, PHP_URL_HOST);
$url = substr_replace($url, $this->remoteIp, strpos($url, $host), strlen($host));
//$url = preg_replace('/^(https?:\/\/)[\w\-\.]+?(\/.*)/i', '${1}'.$this->remoteIp.'$2', $url, 1);
$headers[] = "Host: $host";
}
$ci = curl_init($url); $ci = curl_init($url);
//添加客户端信息以辨服务端识别和调试 //添加客户端信息以辨服务端识别和调试
...@@ -182,7 +191,8 @@ class Client ...@@ -182,7 +191,8 @@ class Client
curl_setopt_array($ci, [ curl_setopt_array($ci, [
CURLOPT_HTTPHEADER => $headers, CURLOPT_HTTPHEADER => $headers,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_0, CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_0,
CURLOPT_IPRESOLVE => CURL_IPRESOLVE_V4 CURLOPT_IPRESOLVE => CURL_IPRESOLVE_V4,
//CURLOPT_DNS_USE_GLOBAL_CACHE => false
]); ]);
//调试 //调试
...@@ -213,7 +223,8 @@ class Client ...@@ -213,7 +223,8 @@ class Client
if ($this->debug) { if ($this->debug) {
echo "<pre>\r\n=====INFO=====\r\n"; echo "<pre>\r\n=====INFO=====\r\n";
echo "Remote Address: {$httpInfo['primary_ip']}:{$httpInfo['primary_port']}\r\n", echo "Request URL: $url\r\n",
"Remote Address: {$httpInfo['primary_ip']}:{$httpInfo['primary_port']}\r\n",
"Local Address: {$httpInfo['local_ip']}:{$httpInfo['local_port']}\r\n", "Local Address: {$httpInfo['local_ip']}:{$httpInfo['local_port']}\r\n",
"Namelookup Time: {$httpInfo['namelookup_time']}\r\n", "Namelookup Time: {$httpInfo['namelookup_time']}\r\n",
"Connect Time: {$httpInfo['connect_time']}\r\n", "Connect Time: {$httpInfo['connect_time']}\r\n",
......
...@@ -14,6 +14,7 @@ return [ ...@@ -14,6 +14,7 @@ return [
], ],
'xue' => [ 'xue' => [
'apiUrl' => 'http://ct.yunya.com/api', 'apiUrl' => 'http://ct.yunya.com/api',
'remoteIp' => '127.0.0.1',
'clientId' => 'common', 'clientId' => 'common',
'clientSecret' => 'Z2oKgZYYc8mznesYMf1o' 'clientSecret' => 'Z2oKgZYYc8mznesYMf1o'
], ],
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment