Delay in logging Drupal user through Services I have two Drupal7 sites. I am using a service that allows a registered user to login using session authentication. 

On the site that performs the call to my remote service I measured the time when I enter the login function and after I got my session id response. It is 6 seconds apart.

When I use the browser to login it works as normal, no delays.
Both Drupal7 instances are running on localhost.

I need some pointers as to where to look in order to reduce this latency.

watchdog("LOG", "Login function hit at " . date(DATE_RFC2822));
$resource = 'access/';

$this-&gt;options = array(
  'headers' =&gt; array(
    'Accept' =&gt; 'application/json',
    'Content-Type' =&gt; 'application/json',
  ),
  'method' =&gt; 'POST',
  'data' =&gt; json_encode(array(
    'username' =&gt; $this-&gt;username,
    'password' =&gt; $this-&gt;password,
  )),
);

$response = drupal_http_request($this-&gt;base_url . $resource . 'user/login', $this-&gt;options);
$data = json_decode($response-&gt;data);

// Check response code
if ($response-&gt;code == 200 &amp;&amp; $data != null) {
  $this-&gt;options['headers']['Cookie'] = $data-&gt;session_name . '=' . $data-&gt;sessid;
  watchdog("LOG", "Connected to remote at " . date(DATE_RFC2822));
}


I wrote a basic php login function to run it from outside a Drupal install and the time to login is 5 seconds. Measured the web login and it's instant. I also switched from Services Resource API 1.0 to 1.1 with no improvements.
This looks unrelated to drupal itself but it's more likely to be a glitch / misconfiguration in the web server/LAMPP settings or a DNS lookup issue.

Can you please let us know more about your LAMPP stack and OS?

Also consider trying the following:


Setting the ServerName property in httpd.conf ( ServerName
  127.0.0.1:80 )   
If the above doesn't work, in your httpd.conf be sure to set the setting HostnameLookups Off
Enable slow query log in MySQL.
Have a look at this post https://serverfault.com/questions/66347/why-is-the-response-on-localhost-so-slow