I am working on a tiny little PHP project for a friend of mine, and I have a WAMP environment setup for local development. I remember the days when the response from my local Apache 2.2 was immediate. Alas, now that I got back from a long, long holiday, I find the responses from localhost painfully slow.

It takes around 5 seconds to get a 300B HTML page served out.

When I look at the task manager, the httpd processes (2) are using up 0% of the CPU and overall my computer is not under load (0-2% CPU usage).

Why is the latency so high? Is there any Apache setting that I could tweak to perhaps make its thread run with a higher priority or something? It seems like it's simply sleeping before it's serving out the response.

  • 1
    Is localhost resolving properly DNS-wise? ping localhost should come back instantaneously with Commented Sep 17, 2009 at 17:25
  • that works fine, response received in <1ms Commented Sep 17, 2009 at 17:36
  • i thought firefox could be the problem, but takes 5s even in IE, so must be either some system setting or Apache setting or gremlins. Commented Sep 17, 2009 at 17:38
  • 3
    Does it have the same behaviour when requesting static content (i.e. when loading http://localhost/index.html)? If not, it might be a PHP issue, not an Apache issue. Commented Sep 17, 2009 at 17:52
  • 5
    What the many, varied answers to this question show is that there are dozens, if not hundreds of different reasons page requests can be slow. If you have arrived at this question because you too have slow page requests, you will need to dig deeper into the cause of the slowness before you can get a useful answer here. strace and tcpdump are useful tools for this.
    – Ladadadada
    Commented Nov 1, 2012 at 12:20

8 Answers 8


For me, setting the ServerName property in httpd.conf fixed the delays (they were up to 10 seconds at worst):

# ServerName gives the name and port that the server uses to identify itself.
# This can often be determined automatically, but we recommend you specify
# it explicitly to prevent problems during startup.
# If your host doesn't have a registered DNS name, enter its IP address here.
  • 12
    This works -- wish I could upvote twice
    – hohner
    Commented May 19, 2012 at 20:46
  • 8
    This fixes it for me too! Gone from 10s latency to 2ms! Commented Jul 2, 2012 at 5:32
  • I struggled for hours and this was the solution. Commented Dec 10, 2013 at 8:51
  • 2
    why is this a problem if localhost resolves properly? what's going on those 10sec before it responds? waiting to time-out somewhere?
    – milan
    Commented Feb 7, 2014 at 12:41
  • 3
    @Elipticalview As the comment in the file says; If your host doesn't have a registered DNS name, enter its IP address here.
    – sshow
    Commented Mar 10, 2014 at 8:13

I had the very same problem.

Setting localhost redirect to in hosts file did not help. Optimizing MySQL server did not help (InnoDB -> MyISAM, changing many cache related directives in my.ini).

Then I used web webgrind and narrowed down the problem to "new PDO(...)" call. Changing




in dsn for PDO completely solved the problem! Page loading time went from over 3000 ms to 16ms.

However I am really confused why the " localhost" line in hosts file did not help.

  • 5
    Can somebody tell me which file I should edit to make it work? Commented Jun 29, 2013 at 20:20
  • 2
    You should edit the line where you are connecting to database (in your PHP script). E.g. change the line: $link = new PDO('mysql:host=localhost;dbname=dp-ui;charset=utf8'); to $link = new PDO('mysql:host=;dbname=dp-ui;charset=utf8');
    – michalko
    Commented Jul 25, 2013 at 14:00
  • I was working on an EXT-JS application recently and has a huge problems of MYSQL data queries taking too long to respond. MYSQL was basically too slow. Thank goodness, Got the answer here..... just changed my host in the connection script from: host = localhost; to host = My server responses went from 3min(180secs) to less thant 1 sec. Thanks alot.
    – user184985
    Commented Aug 9, 2013 at 5:11
  • This solved my problem. Strange... I didn't notice that problem in SQLite Commented Sep 25, 2014 at 15:25
  • 2
    The same for me, but just for WordPress. Had to replace "localhost" with "" in wp-config.php
    – Adrian
    Commented Apr 23, 2015 at 7:12

The issue was with Apache's main settings file httpd.conf.

I found this:

There are three ways to set up PHP to work with Apache 2.x on Windows. You can run PHP as a handler, as a CGI, or under FastCGI. [Source]

And so I went into the Apache's settings and saw where the problem was: I had it set up as CGI, instead of loading it as a module. This caused php-cgi.exe to start up and shut down every time I made a request. This was slowing my localhost development down.

I changed the settings to load PHP as an Apache MODULE and now it all works perfectly. :)

To load the PHP module for Apache 2.x:

1) insert following lines into httpd.conf

LoadModule php5_module "c:/php/php5apache2.dll"

AddHandler application/x-httpd-php .php

(p.s. change C:/php to your path. Also, change php5apache**.dll to your existing file name)

2) To limit PHP execution only for .php files, add this in httpd.conf:

<FilesMatch \.php$> SetHandler application/x-httpd-php </FilesMatch>

3) set path of php.ini in httpd.conf (if after restart you get error, then remove this line again)

PHPIniDir "C:/php"

Thank you all for your efforts.

  • 2
    My Apache stops on adding the lines as mentioned in the Source. How do I do in Windows?
    – AgA
    Commented Apr 2, 2013 at 13:02
  • that link became expired. Use this: goo.gl/2EVth9
    – T.Todua
    Commented Aug 30, 2016 at 9:06
  • how to replicate something on mac? Commented May 29, 2020 at 13:28

Check if /etc/hosts is correct. Like this:

# hostname mobrglnx1 added to /etc/hosts by anaconda localhost localhost.localdomain localhost4 localhost4.localdomain4 *****

::1 localhost localhost.localdomain localhost6 localhost6.localdomain6 *******

In the place **** give your hostname.

  • It was the case for me. My domain was set in ipv4 line, but not in ipv6. Commented Sep 10, 2015 at 0:10
  • Same for me. Requests took > 5 sec before I put the additional line in /etc/hosts. Now my stuff runs in ~0.1 sec.
    – mwallisch
    Commented Oct 17, 2015 at 12:33
  • Put me into the right direction. Added something.atmy.localhost and now request doesn't take 20 seconds anymore. Instead the local apache responds immediately. Don't know that much about networks. I guess the domain name gets resolved too slowly, because something is not correcly configured.
    – robsch
    Commented Nov 13, 2018 at 7:44

I had the same problem and finally discover that it was coming from two facts :

  1. I use Mac OS X Mavericks
  2. I accessed my project via the URL http://myproject.local/ because I put a line myproject.local in /etc/hosts

The problem appears because the .local tld is reserved for Bonjour service, and this since Mac OS X Lion (10.7).

Changing the tld for something else fixed the problem.

  • I use .test but still same problem Commented May 29, 2020 at 13:30
  • @KamelLabiad you should not use it, it is a real top level domain (TLD): fr.wikipedia.org/wiki/.test
    – lepix
    Commented May 29, 2020 at 23:51

In your httpd.conf be sure to set the setting HostnameLookups Off.

  • 7
    i don't seem to have an apache.conf file, also I searched for HostnameLookups directive in all of the files and I found it in the core.html.en manual file. It said it's Off by default, so I guess it's off Commented Sep 17, 2009 at 18:28

In case it helps anyone, I had this problem and it boiled down to being incorrect DNS lookup.

The DNS Server on the server was set to - I changed it to use the Google Public DNS servers, and that made it a whole heap faster.


The question has a tag apache-2.2, but if someone is affected by this nefarious issue also on WAMP with Apache 2.4 + PHP 5.5, the following answer on SO did the trick for me:

edit httpd.conf and disable the loading of the CGI module by commenting this line: LoadModule cgi_module modules/mod_cgi.so


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .