-->
Page 1 of 1

Fast Response on Remote Server Slow Response on Local Server

PostPosted: Wed Mar 20, 2019 8:16 pm
by RussNZ
Hi, I'm having trouble using ESP8266 on a local server but not remote servers. If I GET request a remote server with PHP the response is very fast. If I try to execute the exact same PHP script on a local server (I've tried Windows XAMPP installation and a Raspberry Pi with manually installed Apache and PHP and I've tried two different networks, problem is the same across all).

All the PHP file I'm trying to execute is doing is printing a single character and nothing else. Literally:
Code: Select all<?php echo 'a'; ?>


If I GET request this from somedomain.com/a.php the response is instant.
If I GET request 192.168.1.10/a.php (local server IP) it takes over 5 seconds for the character to be printed. Requesting HTML pages with no PHP is instant on local server, it is only PHP code that is slow.

My Sketch Code:
Code: Select all#include <Wiegand.h>
#include <ESP8266WiFi.h>

// Network Credentials and server IP
const char* ssid = "ssid";
const char* password = "pass";
const char* host = "192.168.1.10";

void setup() {
  Serial.begin(9600);

  Serial.printf("Connecting to the network: %s ", ssid);
  WiFi.begin(ssid, password);
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }
  Serial.println(" successfully connected");
}

void loop() {
  WiFiClient client;

    Serial.printf("\n[Connecting to %s ... ", host);
   
    if (client.connect(host, 80)) {
      Serial.println("connected]");
      Serial.println("[Sending a request]");
      client.print(String("GET /a.php") + " HTTP/1.1\r\n" +
                   "Host: " + host + "\r\n" +
                   "Connection: close\r\n" +
                   "\r\n"
                  );
    }
   
    Serial.println("[Response:]");
   
    while(client.connected() || client.available()) {
      if(client.available()) {
        String line = client.readStringUntil('\n');
        Serial.println(line);
      }
    }
    client.stop();
    Serial.println("\n[Disconnected]");
  }

}

Re: Fast Response on Remote Server Slow Response on Local Se

PostPosted: Sat Mar 23, 2019 8:10 pm
by RussNZ
Thought I'd just update this in case anyone in the future stumbles across this post.

The issue appears to be something to do with Apache, I swapped from Apache to Nginx and the issue went away.

Re: Fast Response on Remote Server Slow Response on Local Se

PostPosted: Sun Mar 24, 2019 10:44 am
by RichardS
Hmm... thanks for the follow up and not leaving us hanging... seems a lot of people post, issues, and when they find solution they just move on.... :?

Thanks!!

RichardS