"127.0.0.1" not equivalent to "localhost"

Trouble during PacsOne Server installations
Post Reply
tburba
Posts:50
Joined:Fri Apr 23, 2010 5:02 pm
Contact:
"127.0.0.1" not equivalent to "localhost"

Post by tburba » Wed Feb 20, 2013 3:12 pm

I was hit by the problem described in detail here:
http://stackoverflow.com/questions/1166 ... s-platform
As a result, php_mysql*.dll connects slowly, with some kind of timeout each time. Our MedDream connects to database in ~1 second instead of a few milliseconds. PacsOne's web interface (6.3.5) does that, too.

The easiest solution for us is to use "127.0.0.1" in our configuration examples and recommendations. Under PacsOne, $AeTitle.ini must be modified. This removes the lag from PacsOne web interface as well. However then the User Administration page creates new users as $UserName@'%' instead of $UserName@'127.0.0.1'. I don't know the exact reason but such MySQL users are unusable and can't connect to the server afterwards, even through mysql.exe. (If I manually create a duplicate entry with $UserName@'localhost', they begin to work.)

The simplest solution in general, as recommended by that webpage, is "bind-address = ::" in my.ini. I'm confirming it works indeed. However this is less desirable as it involves changing the configuration set by the customer -- they might have their own reasons for it.

I took a look into PacsOne's *.php files and found "localhost" hardcoded in numerous locations. Our problem can apparently be remedied by the following single change:

Code: Select all

--- database.php.0	2012-02-10 18:04:32.000000000 +0200
+++ database.php	2013-02-20 14:17:58.000000000 +0200
@@ -1865,7 +1865,9 @@
         return $converted;
     }
     function getHostname() {
-        return strcasecmp($this->hostname, "localhost")? "%" : "localhost";
+        return (strcasecmp($this->hostname, "localhost") && strcasecmp($this->hostname, "127.0.0.1")) ?
+			"%" :
+			$this->hostname;
     }
     function getAutoConvertJPG() {
         $autoconvert = false;
Now users are created adequately, as $UserName@'127.0.0.1', and can log in. Perhaps '::1' should be also added as a separate condition just in case.

However I found a similar validation elsewhere. Also at a few places an empty string is changed to "localhost", though this might be easier to avoid.

Do you see any possible problems with this simple change? Must other locations be fixed as well?

And, of course -- can we expect that you fix the issue in some future version?

pacsone
Site Admin
Posts:3149
Joined:Tue Sep 30, 2003 2:47 am

Post by pacsone » Thu Feb 21, 2013 6:34 pm

This seems to be a IPv6 specific issue with the version of MySQL you are running, as using "localhost" instead of "127.0.01" just makes the problem present itself.

Since MySQL recommends using "localhost" instead of "127.0.0.1" in all of their documentations, and the same "localhost" is used for other databases (e.g., Oracle) as well, we'd like to keep the current default value of "localhost" for hostnames, and wait for MySQL to fix this IPv6 specific issue. As you mentioned above, the workaround is to enable the IPv6 binding ("bind-address = ::") in the my.ini configuration file, which should be enabled by default anyway.

tburba
Posts:50
Joined:Fri Apr 23, 2010 5:02 pm
Contact:

Post by tburba » Thu Feb 21, 2013 9:55 pm

pacsone wrote:MySQL recommends using "localhost" instead of "127.0.0.1" in all of their documentations
I see. Moreover, it's a particular Win32 build of MySQL -- for XAMPP 1.8.1. I will report the issue at their forum.

Post Reply