1

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->options = array(
  'headers' => array(
    'Accept' => 'application/json',
    'Content-Type' => 'application/json',
  ),
  'method' => 'POST',
  'data' => json_encode(array(
    'username' => $this->username,
    'password' => $this->password,
  )),
);

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

// Check response code
if ($response->code == 200 && $data != null) {
  $this->options['headers']['Cookie'] = $data->session_name . '=' . $data->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.

1 Answer 1

1

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:

  1. Setting the ServerName property in httpd.conf ( ServerName 127.0.0.1:80 )
  2. If the above doesn't work, in your httpd.conf be sure to set the setting HostnameLookups Off
  3. Enable slow query log in MySQL.
  4. Have a look at this post https://serverfault.com/questions/66347/why-is-the-response-on-localhost-so-slow
5
  • I'm on Mac OSx 10.9.1, running apache5, PHP 5.4. I'll follow the above and see if it improves.
    – NickO
    Commented Feb 25, 2014 at 11:54
  • I am not sure if this helps but I have virtual hosts in Apache. The web server runs fast when I use it from the browser.
    – NickO
    Commented Feb 25, 2014 at 13:59
  • I think using virtual hosts was the problem. I am now logging through the localhost/website path and it works way faster than having a website.local hostname. I'd like to know if there is any way I can speed it up.
    – NickO
    Commented Feb 25, 2014 at 14:25
  • Have you followed the above ? Those are good practice rules of thumb.
    – Intellix
    Commented Feb 25, 2014 at 14:30
  • 1
    If disabling virtual hosts helped that only confirms that there was a DNS issue causing it.
    – Intellix
    Commented Feb 25, 2014 at 14:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.