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!