Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Localhost rendering pages are very slow

My localhost rendering pages were slow. Everything even simple html rendering was taking around 2-5 seconds. I researched on it and got it fixed by replacing:

new \PDO(... ':host=localhost' ...);

to

new \PDO(... ':host=127.0.0.1' ...);

can anyone explain to me or give me a link to read why localhost was slowing down and how just changing it into IP made it very fast. Right now it renders even complex queries less than a second when it was taking around 5-10 seconds before.

And also is there any security issue by replacing localhost with IP? I mean if i host my project live and i replace localhost with the IP of the host will it have affect on any kind of security?

thanks alot

like image 517
GGio Avatar asked Feb 09 '13 21:02

GGio


1 Answers

I reckon this could have something to do with IPv6 being enable on the server where you run your script. I'm not very strong on network topics, but such issue has been discussed several times.

I looked for an article that could give a better explanation, I think I found one: MySQL and Localhost Performance (it's from 2011, but it still applies in many cases).

like image 186
Diego Avatar answered Sep 24 '22 22:09

Diego