简体   繁体   中英

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

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).

The solution that worked for me was to edit httpd.conf and disable the loading of the CGI module by commenting this line:

LoadModule cgi_module modules/mod_cgi.so

Commenting would be just adding a # in front, like this:

#LoadModule cgi_module modules/mod_cgi.so

Restart the Apache service and you should be good to go.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM