2

Firstly I will try to explain how the setup I am trying to debug works.

  • First off, an XHR/Ajax request is made from the client (JavaScript).
  • This request gets sent off to a Windows/Apache/PHP server
  • This server acts as a proxy, which accepts the request, processes the data and proxies it onto another server, with cURL
  • The cURL request is sent to a Windows IIS server, which accepts the data, and returns some values back to the PHP proxy server
  • The PHP proxy server does some work with the values and then returns them back to the client (JavaScript)

Some other information:

  • The purpose of this PHP cURL proxy is that it is a single sign-on authentication API.
  • The process is much inspired by this answer: How youtube gets logged in to gmail account without redirect?.
  • The PHP cURL proxy acts as the single sign-on API which stores authentication tokens.
  • The Windows IIS server is the place that username/passwords are sent to, and potentially returns an auth token.

The problem:

On the initial request, there is a 30 second wait time until a response is returned, it's almost like the servers are asleep and need waking up. After the initial request successfully gets a response, subsequent requests are returned in less than 1 second. If no requests are made for a space of time (say 30 minutes), the slow initial request happens again.

A direct request to the PHP Auth API never has this long wait, the same goes for the Windows IIS endpoint - but when there's a cURL between the two, the long wait occurs.

Can anyone point me in the right direction here? Maybe it's something obvious that I haven't considered? Would "Keep connection alive" type parameters be of help?

I hope I have explained the problem properly and if more information is needed, just ask.

Thank you Stack Overflow!

enter image description here

Community
  • 1
  • 1
rorymorris89
  • 1,144
  • 7
  • 14
  • try to trace your curl request time using [curl_getinfo](http://php.net/manual/en/function.curl-getinfo.php) method and `CURLINFO_TOTAL_TIME` – hassan Mar 08 '17 at 10:20
  • @HassanAhmed okay I will give that a try, thanks. This is particularly tricky to debug as I have to wait a certain amount of time before the "long wait" can occur again. – rorymorris89 Mar 08 '17 at 10:29
  • "certain amount of time" may occur because a certain amount of data response , however it's just a try to decrease the ways we may walk through to get the real reason . – hassan Mar 08 '17 at 10:49

1 Answers1

1

Have you considered that as this is the 'first' time you have called the API, that the API itself may have just gone to sleep, and its own initialisation has startup steps which take a little time to run.

  • Yeah - I have considered that (quoting my OP "it's almost like the servers are asleep and need waking up"), although really that would be the worst case scenario, as I'd assume it'd be something that can't be fixed. Hopefully it's not that! – rorymorris89 Mar 10 '17 at 10:32
  • Based on further communication with the guys that handle the .NET Auth Provider side of things, this is the exact problem. Thank you! – rorymorris89 Mar 10 '17 at 10:46