【发布时间】:2021-02-20 23:35:02
【问题描述】:
所以我正在使用 azure-storage-php 库 (https://github.com/Azure/azure-storage-php) 并且一切正常,我的所有脚本都可以正常工作,但我不时收到以下错误:
PHP Fatal error: Uncaught GuzzleHttp\Exception\ConnectException: cURL error 7: Failed to connect to fz.blob.core.windows.net port 443: Connection refused (see https://curl.haxx.se/libcurl/c/libcurl-errors.html)
有谁知道我可能做错了什么?以下是我主要基于库的代码:
public function connect()
{
$connection_string = "DefaultEndpointsProtocol=https;
AccountName={$this->account_name};
AccountKey={$this->account_key}";
$blob_client = BlobRestProxy::createBlobService($connection_string);
return $blob_client;
}
public function generate_sas_url(string $blob, string $duration): string
{
$sas_helper = new BlobSharedAccessSignatureHelper(
$this->account_name,
$this->account_key,
);
$token = $sas_helper->generateBlobServiceSharedAccessSignatureToken(
Resources::RESOURCE_TYPE_BLOB,
"$this->container_name/{$blob}",
'r',
(new \DateTime())->modify($duration),
(new \DateTime()),
'',
'https',
);
$connection_string_sas = Resources::BLOB_ENDPOINT_NAME .
'=' .
'https://' .
$this->account_name .
'.' .
Resources::BLOB_BASE_DNS_NAME . ';' .
Resources::SAS_TOKEN_NAME . '=' .
$token;
$blob_client_sas = BlobRestProxy::createBlobService($connection_string_sas);
$blob_url_sas = sprintf(
'%s%s?%s',
(string)$blob_client_sas->getPsrPrimaryUri(),
"$this->container_name/{$blob}",
$token,
);
return $blob_url_sas;
}
【问题讨论】:
-
它有时会在那个 URL 上工作,有时会失败吗?或者它对某些 URL 有效但在其他 URL 上失败?
-
也有这个问题,遗憾的是我再也找不到那个代码了。检查它是否在没有 https 的情况下工作。如果没记错的话,在 azure 中的某处有一个 https 设置。
-
shelly1337 Greg 谢谢大家!我最终找到了问题,看起来我需要在我调用它的任何地方尝试/捕获我的连接。
标签: php azure azure-storage azure-blob-storage