PHP CURL 对 CloudFront 的 GET 请求 URL 非常高的 TTFB
PHP CURL GET request to CloudFront URL very high TTFB
我有一个非常简单的 PHP CURL get 请求从我的 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 有点菜鸟,不知所措。
如果有人能指出正确的方向,我将不胜感激。
在发布我的问题后 2 天 5 分钟,我一直在尝试解决这个问题我决定更改(应该是显而易见的)我的 CloudFront 分发设置中的设置。
解决方案:关闭 IPv6 设置。
我有一个非常简单的 PHP CURL get 请求从我的 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 有点菜鸟,不知所措。
如果有人能指出正确的方向,我将不胜感激。
在发布我的问题后 2 天 5 分钟,我一直在尝试解决这个问题我决定更改(应该是显而易见的)我的 CloudFront 分发设置中的设置。
解决方案:关闭 IPv6 设置。