Skip to content

Commit

Permalink
Merge pull request #7 from tioncico/master
Browse files Browse the repository at this point in the history
七牛云新增超时配置
  • Loading branch information
kiss291323003 authored Dec 12, 2019
2 parents 7046e0f + 342f632 commit 42b6258
Show file tree
Hide file tree
Showing 9 changed files with 56 additions and 10 deletions.
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion phpunit.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,3 @@

defined("QINIU_ACCESS_KEY") ?: define('QINIU_ACCESS_KEY', 'xxx');
defined("QINIU_SECRET_KEY") ?: define('QINIU_SECRET_KEY', 'xxx');

2 changes: 1 addition & 1 deletion src/AliYun/OssClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
42 changes: 40 additions & 2 deletions src/QiNiu/Config.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

namespace EasySwoole\Oss\QiNiu;

final class Config
Expand All @@ -14,9 +15,9 @@ final class Config
const RTCAPI_HOST = 'http://rtc.qiniuapi.com';
const ARGUS_HOST = 'argus.atlab.ai';
const CASTER_HOST = 'pili-caster.qiniuapi.com';
const SMS_HOST="https://sms.qiniuapi.com";
const SMS_HOST = "https://sms.qiniuapi.com";
const RTCAPI_VERSION = 'v3';
const SMS_VERSION='v1';
const SMS_VERSION = 'v1';

// Zone 空间对应的存储区域
public $region;
Expand All @@ -27,6 +28,10 @@ final class Config
// Zone Cache
private $regionCache;

protected static $timeout = 3;

protected static $connectTimeout = 5;

// 构造函数
public function __construct(Region $z = null)
{
Expand Down Expand Up @@ -137,4 +142,37 @@ private function getRegion($accessKey, $bucket)
}
return $region;
}

/**
* @return int
*/
public static function getTimeout(): int
{
return self::$timeout;
}

/**
* @param int $timeout
*/
public static function setTimeout(int $timeout): void
{
self::$timeout = $timeout;
}

/**
* @return int
*/
public static function getConnectTimeout(): int
{
return self::$connectTimeout;
}

/**
* @param int $connectTimeout
*/
public static function setConnectTimeout(int $connectTimeout): void
{
self::$connectTimeout = $connectTimeout;
}

}
3 changes: 2 additions & 1 deletion src/QiNiu/Http/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,6 @@ private static function userAgent()
return $ua;
}


private static function parseHeaders($raw)
{
$headers = array();
Expand Down Expand Up @@ -143,6 +142,8 @@ private static function ucWordsHyphen($str)
}

protected static function clientHandel(HttpClient $httpClient){
$httpClient->setTimeout(Config::getTimeout());
$httpClient->setConnectTimeout(Config::getConnectTimeout());
$httpClient->setHeader('User-Agent',self::userAgent(),false);
}
}
2 changes: 1 addition & 1 deletion src/QiNiu/Region.php
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
Expand Down
6 changes: 3 additions & 3 deletions src/Tencent/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -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']
Expand Down Expand Up @@ -187,15 +187,15 @@ public function setTimeout($timeout): void
*/
public function getConnectTimeout()
{
return $this->connect_timeout;
return $this->connectTimeout;
}

/**
* @param mixed $connect_timeout
*/
public function setConnectTimeout($connect_timeout): void
{
$this->connect_timeout = $connect_timeout;
$this->connectTimeout = $connect_timeout;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion tests/AliYun/test.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
1 change: 1 addition & 0 deletions tests/QiNiu/test.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);

0 comments on commit 42b6258

Please sign in to comment.