Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/295.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/azure/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 未捕获的GuzzleHttp\Exception\ConnectException:cURL错误7_Php_Azure_Azure Storage_Azure Storage Blobs - Fatal编程技术网

Php 未捕获的GuzzleHttp\Exception\ConnectException:cURL错误7

Php 未捕获的GuzzleHttp\Exception\ConnectException:cURL错误7,php,azure,azure-storage,azure-storage-blobs,Php,Azure,Azure Storage,Azure Storage Blobs,因此,我使用的是azure存储phplibrary(),一切都很正常,我的所有脚本都正常工作,但我不时会遇到以下错误: 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

因此,我使用的是
azure存储php
library(),一切都很正常,我的所有脚本都正常工作,但我不时会遇到以下错误:

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;
    }

这似乎解决了这个问题:

public function blob_exists(string $name, string $prefix = ''): int
{
    try {
        $list_blobs_options = new ListBlobsOptions();
        $list_blobs_options->setPrefix($prefix . $name . '.jpg');
        $results = $this->connect()->listBlobs(
            $this->container_name, $list_blobs_options
        );
        return count($results->getBlobs());
    } catch (ConnectException $e) {
        $code = $e->getCode();
        $error_message = $e->getMessage();
        echo $code . ": " . $error_message . PHP_EOL;
        return 0;
    }
}

我有一个方法可以检查blob是否存在,确保尝试/捕获连接器方法,并包括
catch(ConnectException)

它有时对该URL有效,有时失败吗?或者它在一些URL上工作,但在其他URL上失败?也有这个问题,很遗憾,我再也找不到那个代码了。检查它是否在没有https的情况下工作。如果没记错的话,azure中有一个https的设置。Shelly137 Greg谢谢大家!我最终发现了这个问题,似乎我需要尝试/抓住我的连接,无论我在哪里打电话。