发现一个奇怪的问题,在添加了七牛云后,上传图片时,始终会卡60秒,才会出现图片上传成功的提示。
而七牛云后台那边,图片是很快就已经上传上去了的。
分析代码,发现在/crmeb/services/upload/BaseUpload.php文件中,getFileHeaders方法使用了get_headers函数,具体表现为:
get_headers()访问七牛 HTTPS 地址,在 IPv6 DNS 优先但无 IPv6 出口的服务器环境下,导致 PHP 阻塞 60 秒,前端表现为“上传成功但一直转圈”。
我是这样解决的,注释这整方法,重新返回数组。
// 七牛等云存储 文件信息已在上传阶段获得
return [
'size' => $this->fileInfo->size ?? 0,
'type' => $this->fileInfo->type ?? 'image/jpeg'
];
这样修改后,上传就秒返回数据了。
期待官方修复这个问题。
try { $headerArray = get_headers(str_replace('\\', '/', $url), true); if (!isset($headerArray['Content-Length'])) { $header['size'] = 0; } if (!isset($headerArray['Content-Type'])) { $header['type'] = 'image/jpeg'; } if (is_array($headerArray['Content-Length']) && count($headerArray['Content-Length']) == 2) { $header['size'] = $headerArray['Content-Length'][1]; } if (is_array($headerArray['Content-Type']) && count($headerArray['Content-Type']) == 2) { $header['type'] = $headerArray['Content-Type'][1]; }} catch (\Exception $e) {}return $header
