PHP CURL GET request to CloudFront URL very high TTFB

I have a very simple PHP CURL get request to retrieve a json file from my AWS CloudFront distribution.

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

I then have a foreach loop which displays the information contained in the json file.

However, it takes 3.6 minutes for the page to load, it's VERY slow. If I use my S3 origin URL instead of the CF URL the page loads instantly.

I am using this same method on other servers without any issues. The issue only occurs on this server which is using the InterWorx hosting control panel software.

Here is the result of the CURL log:

* 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

It looks like the connection keeps timing out.

It's probably an issue with my CF distribution settings however I am a bit of a noob when it comes to AWS and am at a loss.

If anybody can point me in the right direction that would be greatly appreciated.


Solution 1:

I've been trying to resolve this issue for 2 days and 5 minutes after posting my question I decided to change (what should of been obvious) a setting in my CloudFront distribution setting.

SOLUTION: Turn off the IPv6 setting.

enter image description here