0

Appears to be something to with Apache configuration, swapping to Nginx solved my issue.

I'm getting slow responses when using localhost with a NODEMCU 1.0 and esp8266 WiFi library.

If I GET a PHP file on a remote server the response is almost instantaneous and the output of the PHP file is printed extremely quickly after the HTTP headers. If I GET the same PHP file on localhost the response takes over 5 seconds even if that PHP files is echoing just a single character.

I've tried with XAMPP and a local server configuration on a Raspberry Pi but both have the same slow response speed.

void loop() {
  WiFiClient client;

  if (wiegand.available()) {
    // Convert the code into a suitable type and construct the GET request
    double readWiegand = wiegand.getCode();
    String readWiegandStr = String(readWiegand, 0);
    String httpGet = "GET /verify.php?code=" + readWiegandStr;

    Serial.printf("\n[Connecting to %s ... ", host);

    if (client.connect(host, 80)) {
      Serial.println("connected]");
      Serial.println("[Sending a request]");
      client.print(httpGet + " 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);
        if(line == "ACCEPT") { 
          Serial.println("Code accepted"); 
        } else if (line == "DECLINE") { 
          Serial.println("Code declined");
        }
      }
    }
    client.stop();
    Serial.println("\n[Disconnected]");
  }
  • seems the issue is with the server if two different servers behave differently - perhaps your local server (not localhost, as that actually means something else) isn't closing the connection after sending the response – Jaromanda X Mar 20 at 23:25
  • Thanks for the response, any ideas how I'd go about checking this? – Russ Mar 21 at 4:31
  • check the local server is closing the connection in a timely manner - without knowing anything at all about your local server, the best I can do is suggest you "fix it" :p – Jaromanda X Mar 21 at 4:33
  • I 'fixed it' by uninstalling Apache and installing Nginx, instant response with Nginx, thank you for the suggestions. – Russ Mar 21 at 5:10
  • So much can be fixed by removing Apache :p – Jaromanda X Mar 21 at 5:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.