Hey there guys, 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 I that got back from a long, long holiday, I find the responses from localhost painfully slow. It takes like 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 CPU and overall my computer is not under load (0-2% CPU usage). Why are the responses so slow? 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 just sleeping for a couple of seconds before it serves out the response.

Any help would be much appreciated, as I am wasting way too much time on this tiny PHP project.

link|improve this question
feedback

9 Answers

up vote 5 down vote accepted

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

I found this:

There are two ways to set up PHP to work with Apache 2.0.x on Windows. One is to use the CGI binary the other is to use the Apache module DLL. In either case you need to edit your httpd.conf to configure Apache to work with PHP and then restart the server. [PHP DOCS]

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 the php-cgi.exe start up and shut down everytime I made a request. This was slowing my localhost-development down.

Changed the settings to load PHP as Apache MODULE and now it all works perfectly :) Thank you all for your efforts.

link|improve this answer
Thank you for this explanation. It was very annoying. – Mert Nuhoglu Jun 29 '10 at 15:01
feedback

Same behaviour, when requesting static content (ie. http://localhost/index.html)? So, might be an php issue?

link|improve this answer
seems to be pointing in the right direction, a 30k html file loads almost instantaneously while a small php script is awfully slow. Any ideas what could be wrong with my php installation? – MasterPeter Sep 17 '09 at 18:32
now i'm quite convinced it's php. thanks, i'll go from here (maybe will need to raise another question soon :)) – MasterPeter Sep 17 '09 at 18:39
well, first start with a simple <? phpinfo(); ?> to check whether it's your skript or php in general... phpinfo should also load quiet fast – Marcus Spiegel Sep 17 '09 at 19:42
feedback

For me, setting the ServerName property in httpd.conf fixed the delays (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.
ServerName 127.0.0.1:80
link|improve this answer
This works -- wish I could upvote twice – Jamie May 19 at 20:46
feedback

In your apache.conf be sure to have HostnameLookups Off

link|improve this answer
1  
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 – MasterPeter Sep 17 '09 at 18:28
feedback

In case it helps anyone, I had this problem and it boiled down to incorrect DNS LOOKUP. The DNS Server on the server was set to 127.0.0.1 - I changed it to use Google DNS Servers and it got a whole heap faster.

link|improve this answer
feedback

Is localhost properly resolving DNS-wise? "ping localhost" should come back instantaneously with 127.0.0.1.

link|improve this answer
that works fine, response received in <1ms – MasterPeter Sep 17 '09 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. – MasterPeter Sep 17 '09 at 17:38
Can you check your apache logs? Do you see the source address of the requestor, is it 127.0.0.1 or the IP of the machine? If the latter, apache might be a reverse DNS lookup before responding. Worth checking httpd.conf for that. – Alexis Lê-Quôc Sep 17 '09 at 18:00
i found the following in the access log: 127.0.0.1 - - [17/Sep/2009:20:17:16 +0200] "GET /index.html HTTP/1.1" 200 132, so i guess everything is okay and the requestor is 127.0.0.1 – MasterPeter Sep 17 '09 at 18:27
feedback

Is there a chance you are trying to reach the server from a local lan box using http://hostname.localdomain/project/test.php ? If that is so, which nameservers do you have at the box running apache ? Local nameservers or the ones provided by the ISP ? If you have 2 NS at the box and the first one is down, windows does not switch all the following requests to the second nameserver, it will always talk to the first NS, wait for timeout and the probe the second NS. Make sure every name server you have specified is up and running.

If not, are you using http://localhost/project/test.php or http://127.0.0.1/project/test.php ?

Do you have HostnameLookups On as a directive ?

link|improve this answer
I tried both localhost and 127.0.0.1 but no difference. I am going to check out the HostnameLookups directive – MasterPeter Sep 17 '09 at 18:19
feedback

If you are using any type of cms make sure to disable reverse dns querying in the db.

link|improve this answer
feedback

I had the same problem, this article had the answer. http://cubicspot.blogspot.com/2010/07/fixing-slow-apache-on-localhost-under.html

link|improve this answer
Linking to the article is good, but you should also summarize it into a meaningful answer. – Scott Pack Mar 15 '11 at 13:30
feedback

Your Answer

 
or
required, but never shown

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