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

March 13, 2018 474 views
Node.js PHP DigitalOcean MySQL Ubuntu 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
  • Are you seeing the same behavior when accessing http://222.222.222.222/search.php directly?

Be the first one to answer this question.