Commit ef61a914 by 庄欣

CURL客户端加了超时选项

parent d0b85510
...@@ -20,6 +20,7 @@ class ControllerBase ...@@ -20,6 +20,7 @@ class ControllerBase
{ {
public function getAuth() public function getAuth()
{ {
return 3;
return request("uuid",3); return request("uuid",3);
static $id; static $id;
if (!$id) { if (!$id) {
...@@ -41,9 +42,7 @@ class ControllerBase ...@@ -41,9 +42,7 @@ class ControllerBase
$uid = $this->getAuth(); $uid = $this->getAuth();
$query .= "&uid=" . $uid; $query .= "&uid=" . $uid;
} }
$client->setUrl($this->prefix."?".$query); $res = $client->get($this->prefix."?".$query);
$client->setMethod("get");
$res = $client->curl();
$res = $this->after_hook($res); $res = $this->after_hook($res);
return Response::success($res); return Response::success($res);
} catch (\Exception $e) { } catch (\Exception $e) {
......
...@@ -84,6 +84,7 @@ class CurlClient ...@@ -84,6 +84,7 @@ class CurlClient
curl_setopt($http,CURLOPT_URL,$this->base.$this->url); curl_setopt($http,CURLOPT_URL,$this->base.$this->url);
curl_setopt($http,CURLOPT_HEADER,false); curl_setopt($http,CURLOPT_HEADER,false);
curl_setopt($http,CURLOPT_CUSTOMREQUEST,$this->method); curl_setopt($http,CURLOPT_CUSTOMREQUEST,$this->method);
curl_setopt($http,CURLOPT_TIMEOUT ,3);
if ($this->format == "JSON") if ($this->format == "JSON")
{ {
$this->header = array_merge($this->header,['Content-Type:application/json']); $this->header = array_merge($this->header,['Content-Type:application/json']);
...@@ -93,7 +94,9 @@ class CurlClient ...@@ -93,7 +94,9 @@ class CurlClient
curl_setopt($http,CURLOPT_POST,true); curl_setopt($http,CURLOPT_POST,true);
} }
curl_setopt($http,CURLOPT_HTTPHEADER,$this->header); curl_setopt($http,CURLOPT_HTTPHEADER,$this->header);
curl_setopt($http,CURLOPT_POSTFIELDS,$this->data); if (!empty($this->data)) {
curl_setopt($http, CURLOPT_POSTFIELDS, $this->data);
}
/*if ($this->method === "GET") { /*if ($this->method === "GET") {
$NOW_TIME = time(); $NOW_TIME = time();
static $response_from_api; static $response_from_api;
......
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