I have a local Ubuntu server hosting internal staging sites. One particular site (www.sitename.com) was taking a long time making the initial connection and we couldn’t figure out why.
The first thing I did was open Firefox and enable Firebug. I noticed that initial GET was taking 5.1 seconds. Disable browser cache, refresh, 5.2 seconds, refresh, 5.0 seconds, 5.2, see a pattern here? First thing that came to my mind was to check the apache2 process to see if there was anything fishy.
top -u www-data
Nothing out of the ordinary here. My swap disks weren’t heavily used and I had plenty of memory free, but just to be sure it wasn’t a stuck Apache process I restarted it.
sudo /etc/init.d/apache2 restart
Refresh page, 5.2 seconds — as expected.
(I did think about using mytop to see if mySQL was the culprit but thought the following would be a quicker way.)
Now I’m thinking maybe it has something to do with the index.php file being loaded, let me upload a text file with “Hello, World” and see if it still takes 5.2 seconds to load. Yup, 5 seconds. Wonderful at least we’re getting some where and narrowing it down.
At this point, I’m asking myself, “Alright what else loads before anything else?” .htaccess! I went ahead, removed the .htaccess file, refreshed the page, and bam 6ms load time.
Well, it turns out that the “deny from” lines were causing this 5 second lag in load time. At this point I have no idea why this is the case but commenting them out definitely solved the problem.
Now to figure out why…