【问题标题】:PHP CURL GET request to CloudFront URL very high TTFB对 CloudFront URL 的 PHP CURL GET 请求非常高 TTFB
【发布时间】:2022-01-20 21:53:08
【问题描述】:

我有一个非常简单的 PHP CURL 获取请求来从我的 AWS CloudFront 分配中检索一个 json 文件。

public function get_directory() {
        $json = 'https://d108fh6x7uy5wn.cloudfront.net/themes.json';
        $curl = curl_init();
        curl_setopt($curl, CURLOPT_URL, $json);
        curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
        $array = curl_exec($curl);
        curl_close($curl);
        $array = json_decode($array, true);
        $array = $array['themes'];
        return $array;
}

然后我有一个 foreach 循环,它显示 json 文件中包含的信息。

但是,页面加载需要 3.6 分钟,非常慢。如果我使用我的 S3 原始 URL 而不是 CF URL,页面会立即加载。

我在其他服务器上使用相同的方法没有任何问题。该问题仅出现在使用 InterWorx 主机控制面板软件的服务器上。

这是 CURL 日志的结果:

* About to connect() to d108fh6x7uy5wn.cloudfront.net port 443 (#0)
*   Trying 2600:9000:2132:4e00:14:45cf:19c0:21...
* Connection timed out
*   Trying 2600:9000:2132:7000:14:45cf:19c0:21...
* Connection timed out
*   Trying 2600:9000:2132:2400:14:45cf:19c0:21...
* Connection timed out
*   Trying 2600:9000:2132:2c00:14:45cf:19c0:21...
* Connection timed out
*   Trying 2600:9000:2132:9600:14:45cf:19c0:21...
* Connection timed out
*   Trying 2600:9000:2132:3000:14:45cf:19c0:21...
* Connection timed out
*   Trying 2600:9000:2132:aa00:14:45cf:19c0:21...
* Connection timed out
*   Trying 2600:9000:2132:5c00:14:45cf:19c0:21...
* Connection timed out
*   Trying 13.224.38.161...
* Connected to d108fh6x7uy5wn.cloudfront.net (13.224.38.161) port 443 (#0)
* Initializing NSS with certpath: sql:/etc/pki/nssdb
*   CAfile: /etc/pki/tls/certs/ca-bundle.crt
  CApath: none
* SSL connection using TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256
* Server certificate:
*   subject: CN=*.cloudfront.net
*   start date: Mar 19 00:00:00 2021 GMT
*   expire date: Mar 17 23:59:59 2022 GMT
*   common name: *.cloudfront.net
*   issuer: CN=Amazon,OU=Server CA 1B,O=Amazon,C=US
> GET /themes.json HTTP/1.1
Host: d108fh6x7uy5wn.cloudfront.net
Accept: */*

< HTTP/1.1 200 OK
< Content-Type: application/json
< Content-Length: 68529
< Connection: keep-alive
< Last-Modified: Tue, 21 Dec 2021 12:05:12 GMT
< Accept-Ranges: bytes
< Server: AmazonS3
< Date: Thu, 20 Jan 2022 09:52:02 GMT
< ETag: "8d0a0de6a39c797d137171347dd8ef52"
< X-Cache: Hit from cloudfront
< Via: 1.1 ce475d5a085e50a2b454f6aec0f8826e.cloudfront.net (CloudFront)
< X-Amz-Cf-Pop: YTO50-C1
< X-Amz-Cf-Id: Bmq-SnHe7-eqfiBf6a6qdoRMQExdhweFLipeL_PrZqM2slQG9OGWzg==
< Age: 34974
< 
* Connection #0 to host d108fh6x7uy5wn.cloudfront.net left intact

连接似乎一直超时。

这可能是我的 CF 分发设置的问题,但是当涉及到 AWS 时我有点菜鸟并且不知所措。

如果有人能指出我正确的方向,将不胜感激。

【问题讨论】:

    标签: php amazon-web-services curl amazon-cloudfront


    【解决方案1】:

    在发布问题 2 天 5 分钟后,我一直在尝试解决此问题,我决定更改(应该很明显)我的 CloudFront 分配设置中的一个设置。

    解决方案:关闭 IPv6 设置。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-06-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-18
      相关资源
      最近更新 更多