4

I have set up a local server using 'Uniform Server Z'. It suits my needs better than WAMP and XAMPP.

I am very happy with it apart from 1 thing - it's very slow. It takes over 2 seconds between request and download for any of my webpages.

I realised if I use "127.0.0.1" to connect to my mysql database (using PDO) it's much quicker (request time from ~2s to <5ms)

I can't work out why it's taking so long to resolve 'localhost'. If I ping 'localhost' it takes <1ms. I assume there must be a setting in Uniform Server Z that is different to that of WAMP and XAMPP.

  • I've tried 'HostnameLookups Off' in httpd.conf and 'skip-name-resolve' in my.ini.
  • I've tried reverting my hosts file back to just simply 127.0.0.1 localhost.
  • I've tried removing all instances of VirtualHosts in the apache confs.
  • I don't use .htaccess.
  • If I use 127.0.0.1 in my web address bar in Chrome I get the same results.

Nothing I've tried has worked.

I know the obvious answer is replace 'localhost' with '127.0.0.1' but there are 3rd party php scripts used by my site that refer to 'localhost' and some that refer to '127.0.0.1'. I'd prefer to leave them as they are.

Can anyone think of any other settings that might resolve the issue?

hedgehog90
  • 1,402
  • 19
  • 37
  • What do you get when you `var_dump($_SERVER['SERVER_ADDR']);`? – HPierce Sep 18 '15 at 17:40
  • possible duplicate of [mysql\_connect (localhost / 127.0.0.1) slow on Windows platform](http://stackoverflow.com/questions/11663860/mysql-connect-localhost-127-0-0-1-slow-on-windows-platform) (The solution provided here should also work with PDO) – HPierce Sep 18 '15 at 17:47
  • @HPierce $_SERVER['SERVER_ADDR'] = ::1 – hedgehog90 Sep 18 '15 at 17:59
  • I bet your MySQL configuration is set to accept IPv4 address while that is using an IPv6 address. The duplicate I linked goes into way more detail -hence why I'm not posting as an answer. [But you can probably just change a `my.ini` setting to `bind-address=*` to accept both IPv4 and IPv6 connections.](https://dev.mysql.com/doc/refman/5.7/en/server-options.html#option_mysqld_bind-address) – HPierce Sep 18 '15 at 18:02
  • If I change 'bind-address' to *, it has some problems, mysql process freezes or if I turn on apache afterwards it shutsdown the mysql process. If I set 'bind-address' to '::' then it works flawlessly. Problem solved! Why is my SERVER_ADDR ::1, with XAMPP I think it was 127.0.0.1. I'd like to stick with ipv4 if i could, is there a way I can tell php/apache to use 127.0.0.1? – hedgehog90 Sep 18 '15 at 18:06
  • Bare in mind, any server that references mysql with `127.0.0.1` is going to struggle with the slow loading times too. I've no idea how to shift apache/php to only use IPv4 unfortunately. – HPierce Sep 18 '15 at 18:11
  • 1
    I tell a lie - if I set 'bind-address' to '::' the MySQL process is unstoppable. As in - I press 'stop MySQL' and then it hangs for about 30 seconds, then it says I have to kill the process. Unfortunately UniServer Z doesn't like either value. – hedgehog90 Sep 18 '15 at 18:17
  • The problems worse than I thought - if I set bind-address to ::1 or :: I can't even use phpMyAdmin. I get the error 'MySQL said: Cannot connect: invalid settings' I have no idea what to do. – hedgehog90 Sep 19 '15 at 11:16

0 Answers0