CURL get request from server to AWS CloudFront very slow response time

0

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 over 120 seconds 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.

The code resides on the server as a plugin for InterWorx, so located here /usr/local/interworx/plugins/wordpress

It seems it could be 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.

asked 2 years ago1196 views
1 Answer
0

You're right - 120 seconds is a very long time. If you instrument your code; or run curl with some logging where is the time being spent? Is it DNS lookup? Other protocol negotiation? Those sorts of details will help determine where you should investigate further.

profile pictureAWS
EXPERT
answered 2 years ago
  • @Brettski@AWS I opened up my Chrome Developer Tools in the Network tab and noticed the Time To First Byte (TTFB) is 3.6 minutes. This ONLY occurs when I use my CloudFront distribution URL, it loads quickly with my S3 URL. Could this be due to a setting in my CF distribution behavior settings? Cache policy and origin request policy?

  • This is the log result when I turn on VERBOSE for the curl get request:

    • 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, 2

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions