Tuesday, June 28, 2016

apache 2.2 - Why is the response on localhost so slow?



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.



Answer



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:




SetHandler application/x-httpd-php




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.


No comments:

Post a Comment

linux - How to SSH to ec2 instance in VPC private subnet via NAT server

I have created a VPC in aws with a public subnet and a private subnet. The private subnet does not have direct access to external network. S...