Question

TTFB on whatwg-fetch request from NodeJS app is over 15 seconds every time. What am I doing wrong?

Posted March 13, 2018 1.5k views
MySQLPHPNode.jsDigitalOceanUbuntu 16.04

I am making a whatwg-fetch request from my React application served up at 111.111.111.111 like so:

    fetch('http://222.222.222.222/search.php', {
      credentials: 'include',
      method: 'POST',
      headers: {
        'Content-Type': 'application/json'
      },
      body: JSON.stringify({
        SearchValue: this.props.SearchValue,
        SearchOption: this.props.SearchOption,
      })
    })
    .then(response => response.json())
    .then(data => {
      console.log(data);
    })

On the other end (at 222.222.222.222) I have this:


<?php 
require_once('initialize.php');
header("Access-Control-Allow-Credentials: true");
header("Access-Control-Allow-Origin: http://111.111.111.111");
header("Access-Control-Allow-Methods: POST, GET, OPTIONS");
header("Access-Control-Allow-Headers: content-type");
header("Access-Control-Max-Age: 86400");

/* Prepared Statement (not very complicated, returns 5 results) */

For some reason the server takes 15 seconds to respond to my fetch request. It takes 15 seconds (most of the time) just to get the first byte back from the responding server. What am I doing wrong? How do I use fetch to get data from my database in JSON format?

1 comment

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

×
1 answer

Hi @donaldwaynemoorejr,

Please make sure you are not making any external requests which might be slowing down the application.

One other suggestion I have after some research and it seems the problem is related with the way Chrome uses connections, if you are checking this with a Chrome browser that might be reason behind it.

Submit an Answer