problem description
sometimes it takes 2s to upload the same file (32kb), but sometimes it takes 11s. The upload speed is too unstable and too slow.
the upload process is that the front end uploads the file to the interface of the back-end php (using yii2 framework), and the php calls the sdk upload method of qiniu. After investigation, the time for the front end to upload files to the server where the php backend is located is very short in a few hundred milliseconds, which is negligible. I would like to ask why the process of uploading to Qiniu is so slow and how to solve this problem. Because the system is about to be used, it is still urgent to upload.
the environmental background of the problems and what methods you have tried
it has been checked that the time for uploading files to the server from the front end is not slow, and the network speed has also been checked.
related codes
/ / Please paste the code text below (do not replace the code with pictures)
php
/ *
- Qiniu Cloud storage components
*
* /
namespace appcommoncomponents;
use Yii;
use yiibaseComponent;
use QiniuAuth;
use QiniuStorageUploadManager;
class Qiniu extends Component
{
public $accessKey;
public $secretKey;
public $auth;
public $defaultBucket;
public $privateBucket;
public $cdnHost;
public function init()
{
parent::init();
$this->auth = new Auth($this->accessKey, $this->secretKey);
}
/**
*
*
* @param string $filePath
* @param string $key
*
* @return string
*/
public function upload($filePath, $key, $bucket = null)
{
$uploadMgr = new UploadManager();
$bucket = empty($bucket) ? $this->defaultBucket : $bucket;
$token = $this->auth->uploadToken($bucket);
list($ret, $err) = $uploadMgr->putFile($token, $key, $filePath);
if ($err !== null) {
Yii::$app->response->error(
Yii::$app->response->resCode["ERROR_QINIU_UPLOAD_FAILED"],
"Upload to qiniu failed."
);
} else {
return $ret["key"];
}
}
/**
* CDN URL
*
* @param string $key
*
* @return string
*/
public function generateUrl($key, $hostType = "default")
{
return !empty($key) ? $this->cdnHost[$hostType] . trim($key, "/") : "";
}
}
what result do you expect? What is the error message actually seen?
uploading dozens of kb files is not so slow. I hope someone can help solve this situation. Thank you.