From 342f632e3e91b77f79366ba8b994162a07d400a7 Mon Sep 17 00:00:00 2001 From: tioncico <1067197739@qq.com> Date: Thu, 12 Dec 2019 14:08:33 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=83=E7=89=9B=E4=BA=91=E6=96=B0=E5=A2=9E?= =?UTF-8?q?=E8=B6=85=E6=97=B6=E9=85=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 7 +++++++ phpunit.php | 1 - src/AliYun/OssClient.php | 2 +- src/QiNiu/Config.php | 42 +++++++++++++++++++++++++++++++++++++-- src/QiNiu/Http/Client.php | 3 ++- src/QiNiu/Region.php | 2 +- src/Tencent/Config.php | 6 +++--- tests/AliYun/test.php | 2 +- tests/QiNiu/test.php | 1 + 9 files changed, 56 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index a3bcd3e..b18970f 100644 --- a/README.md +++ b/README.md @@ -63,6 +63,13 @@ go(function (){ - PfopTest 类方法未走通,提示{"error":"no such bucket"} - \EasySwoole\Oss\Tests\QiNiu\ResumeUpTest::test4ML2 方法未走通,一直卡住,不建议使用该方法上传文件,请使用 \EasySwoole\Oss\Tests\QiNiu\ResumeUpTest::test4ML 方法上传 +### 七牛云设置超时 +官方sdk没有设置超时的逻辑,在本组件中新增加了,设置方法如下: +```php +\EasySwoole\Oss\QiNiu\Config::setTimeout(3); +\EasySwoole\Oss\QiNiu\Config::setConnectTimeout(5); +``` + ## 腾讯云调用 腾讯云调用和原来的方法基本一致,操作文档可直接查看腾讯云官方文档:https://cloud.tencent.com/document/product/436/12266 diff --git a/phpunit.php b/phpunit.php index ac7d249..e83485d 100644 --- a/phpunit.php +++ b/phpunit.php @@ -15,4 +15,3 @@ defined("QINIU_ACCESS_KEY") ?: define('QINIU_ACCESS_KEY', 'xxx'); defined("QINIU_SECRET_KEY") ?: define('QINIU_SECRET_KEY', 'xxx'); - diff --git a/src/AliYun/OssClient.php b/src/AliYun/OssClient.php index 9a8fa8e..89f349c 100644 --- a/src/AliYun/OssClient.php +++ b/src/AliYun/OssClient.php @@ -1968,13 +1968,13 @@ public function auth(array $options) //创建请求 $httpClient = new HttpClient(); $httpClient->setTimeout($this->timeout);; + $httpClient->setConnectTimeout($this->connectTimeout);; //请求链接 $httpClient->setUrl($this->requestUrl); //设置http请求方法 $this->setHttpClientMethod($httpClient, $options); //设置http请求内容 $this->setHttpClientData($httpClient, $options); - $httpClient->setConnectTimeout($this->connectTimeout);; //清除原有header并设置user-agent $httpClient->setHeader('User-Agent', $this->generateUserAgent(), false); $httpClient->setHeader('Referer', $this->requestUrl); diff --git a/src/QiNiu/Config.php b/src/QiNiu/Config.php index d2773a3..9fec97f 100644 --- a/src/QiNiu/Config.php +++ b/src/QiNiu/Config.php @@ -1,4 +1,5 @@ setTimeout(Config::getTimeout()); + $httpClient->setConnectTimeout(Config::getConnectTimeout()); $httpClient->setHeader('User-Agent',self::userAgent(),false); } } diff --git a/src/QiNiu/Region.php b/src/QiNiu/Region.php index 19bc77d..470d5e1 100644 --- a/src/QiNiu/Region.php +++ b/src/QiNiu/Region.php @@ -144,7 +144,7 @@ public static function queryRegion($ak, $bucket) { $Region = new Region(); $url = Config::API_HOST . '/v2/query' . "?ak=$ak&bucket=$bucket"; - $ret = Client::Get($url); + $ret = Client::get($url); if (!$ret->ok()) { return array(null, new Error($url, $ret)); } diff --git a/src/Tencent/Config.php b/src/Tencent/Config.php index 08a468e..5d814b1 100644 --- a/src/Tencent/Config.php +++ b/src/Tencent/Config.php @@ -15,7 +15,7 @@ class Config extends SplBean protected $anonymous=false;//匿名 protected $token="";//token protected $timeout=3600;//超时时间 - protected $connect_timeout;//连接超时时间 + protected $connectTimeout;//连接超时时间 protected $ip=null;//ip protected $port=null;//端口 protected $proxy= null;//是否代理 http代理 $proxy=['127.0.0.1','8080','user','pass'] @@ -187,7 +187,7 @@ public function setTimeout($timeout): void */ public function getConnectTimeout() { - return $this->connect_timeout; + return $this->connectTimeout; } /** @@ -195,7 +195,7 @@ public function getConnectTimeout() */ public function setConnectTimeout($connect_timeout): void { - $this->connect_timeout = $connect_timeout; + $this->connectTimeout = $connect_timeout; } /** diff --git a/tests/AliYun/test.php b/tests/AliYun/test.php index 9ff0882..0d94556 100644 --- a/tests/AliYun/test.php +++ b/tests/AliYun/test.php @@ -16,6 +16,6 @@ 'endpoint' => END_POINT, ]); $client = new \EasySwoole\Oss\AliYun\OssClient($config); - $data = $client->putObject('tioncicoxyz','test11',__FILE__); + $data = $client->uploadFile('tioncicoxyz','test1112.jpg','/www/easyswoole/tioncico_oss/tests/Img/test.jpg'); var_dump($data); }); \ No newline at end of file diff --git a/tests/QiNiu/test.php b/tests/QiNiu/test.php index ebcaa45..44429d4 100644 --- a/tests/QiNiu/test.php +++ b/tests/QiNiu/test.php @@ -9,6 +9,7 @@ include "../../phpunit2.php"; $auth = new \Qiniu\Auth(QINIU_ACCESS_KEY,QINIU_SECRET_KEY); + $bucketManager = new \Qiniu\Storage\BucketManager($auth); list($list, $error) = $bucketManager->buckets(); var_dump($list); \ No newline at end of file