6

The simplest script:

<?php echo 'hello';

Takes about 3 seconds to execute. There seems to be a big time interval Apache waits until it serves a web page.

I tried turning off antivirus, disabling ipv6 and more but Apache is still very slow. What should I do?

EDIT:

Additional information:

  • Apache 2.2
  • PHP 5.2
  • It's only dynamic PHP files. Static files (html) are served instantly
  • It has nothing to do with system specs, it's new PC

There are few PHP notices in Apache error log:

[Thu Jul 01 08:37:21 2010] [error] [client 127.0.0.1] PHP Notice:  Undefined variable: ref in D:\\data\\o\\WebProjects\\elearning\\application\\modules\\clientarea\\controllers\\ViewController.php on line 578, referer: http://elearning/clientarea/view/course/teid/1/cid/1
Charles
  • 50,943
  • 13
  • 104
  • 142
Richard Knop
  • 81,041
  • 149
  • 392
  • 552
  • What are your system specs? Which browser and version are you using? – mcandre Jun 29 '10 at 13:42
  • And what versions of Apache and PHP are you running? – Mark Baker Jun 29 '10 at 13:46
  • install a LAMP stack on a virtual machine and test there! (try reïnstalling wampstack maybe something went wrong with the install?) – Redlab Jun 29 '10 at 13:48
  • when you say "until it serves a web page." is it only for PHP files or also for static html? – Redlab Jun 29 '10 at 13:49
  • 1
    Have you checked the Apache error log? – Powerlord Jun 29 '10 at 14:16
  • Is PHP running in-server, or as a CGI engine? If it's running as CGI, there'll be a time hit to fire up PHP.exe for every page request. Plus running as CGI will kill any ability to cache the compiled script in memory (via APC or whatever). – Marc B Jun 29 '10 at 17:29
  • Its'running as CGI but the time to fire up canot be this long. It can't take 5+ seconds to fire up php executable on quad core pc with lots of ram. – Richard Knop Jul 01 '10 at 06:58
  • @R. Bemrose: There are just few PHP notices, I have included them in my question. – Richard Knop Jul 01 '10 at 07:00

7 Answers7

14

It's commonly suggested that this problem is caused by your firewall interfering or by having IPv6 enabled at your network interfaces, however those solutions didn't fix the issue for me. It turns out that by default Windows 7 hosts file at "C:\Windows\System32\drivers\etc\hosts" has this line commented out:

# 127.0.0.1 localhost

In my case, simply uncommenting this line changed the localhost performance back to what it was supposed to be, instead of that annoying 3-5 second wait on every page load. Remember that you need to run your text editor with administrator rights to edit the hosts file.

Fuu
  • 3,424
  • 4
  • 33
  • 49
  • Recommend to comment the line ::1 as well. It is a real shame to MS, sorry to say. Now my internet connection is faster than before because of this stupid thing. – Codebeat May 13 '13 at 02:24
5

I had the same issue. Modifying the host file did not improve pages loading speed. After searching for hours, I finally found a solution.

I changed my httpd.conf file so that the listen address is bound to one IP address instead of all available interfaces :

#Listen 80
Listen 127.0.0.1:80

Now all the webpages are loading instantaneously instead of ~10 seconds.

Hope this help.

Edit : actually it did not solve the issue, it was still randomly slow. I have to admit that I finally moved my webserver to a linux virtual machine on which I never observed any slow response time anymore.

Juljan
  • 802
  • 2
  • 8
  • 13
3

I´m using Laravel Framework, what worked for me was changing directive realpath_cache_size = 1M in the php.ini. It changed loading time from 3 seconds to half second!

realpath_cache_size = 1M

ebelendez
  • 848
  • 2
  • 12
  • 22
0

In my case, by default, the standard documents root C:\PathToApache\htdocs was shared with other users on the local network. By disabling the sharing of that directory I've improved a lot Apache's performances. Now each request take less than a blink of an eye.

I hope this will help all of you future readers

Giova
  • 1,879
  • 1
  • 19
  • 27
0

Purely to help anyone who comes across this dilemma of Apache being slow on Windows, I solved this by commenting out ::1 localhost in C:\Windows\System32\drivers\etc\hosts and adding 127.0.0.1 127.0.0.1.

I found I kept having to reload Apache in Windows Services because my websites would gradually respond slower and slower.

The Apache htdocs folder was not shared, changing the Listen ... line in httpd.conf didn't seem to work, and I already had the line 127.0.0.1 localhost in my C:\Windows\System32\drivers\etc\hosts file, but the ::1 localhost line was directly below it.

As @Erwinus recommends in his comment on the top post, I commented out that line and from this post I added the line 127.0.0.1 127.0.0.1. The server response time appears to have improved massively.

Community
  • 1
  • 1
jonbaldie
  • 378
  • 5
  • 12
0

The only thing helped me is un-ticking box 'register this connection's addresses in dns' in ipv4 parameters of the network adapter, button under DNS settings -> lower two checkboxes.

kazanart
  • 46
  • 5
-11

Use the Task Manager to kill unnecessary processes.

By the way, you should end your script with ?>.

mcandre
  • 22,868
  • 20
  • 88
  • 147
  • 4
    A trailing ?> is unnecessary (though some people might argue over whether or not it's good practise) and can actually cause problems in some cases if there are spaces after the ?> So I prefer not to have it – Mark Baker Jun 29 '10 at 13:48
  • 10
    Not to be 'one of those guys', but leaving off the ?> is acceptable and actually recommended by a number of coding standards. For one, it ensures no trailing whitespace ends up pushing output before headers, for example. – Narcissus Jun 29 '10 at 13:48