ezpublish-legacy
ezpublish-legacy copied to clipboard
Fix EZP-20375 by forcing servername to be resolved with its ip address
See http://php.net/manual/en/mysqli.construct.php
Note:
Specifying the socket parameter will not explicitly determine the type of connection to be used when connecting to the MySQL server. How the connection is made to the MySQL database is determined by the host parameter.
site.ini.[DatabaseSettings].Server = localhost site.ini.[DatabaseSettings].Socket = disabled
results in having in lib/ezdb/classes/ezmysqlidb.php
$socketPath = false $server = localhost
=> meaning that mysqli_connect( $server, $user, $password, null, (int)$port, $socketPath );
will try to connect through the default socket instead of using a tcp/ip connection.
This patch forces a tcp/ip connection by passing an ip address to mysqli_connect()
instead of localhost
which means more than a simple hostname in that case.
How big cost is there to use gethostbyname(), would it be better to log a error on this instead of a warning?
Good catch. The case i'm trying to address should only be triggered when server = localhost and socket=disabled so I might think that DNS resolution in that cas would not be time consuming, but i might be wrong.
Well, so the solution will depend on what you want to do when such a case occured. Would you prefer the user to see a fatal error or something visually working with a warning/error logged inviting him to change its database configuration ?
Also, I'm thinking that site.ini.[DatabaseSettings].Socket could be :
-
system
: use system configuration and default setting -
/path/to/socket
: use the specified socket -
disabled
(currently the default one) : force socket to not be used (which cannot be really the case today and could be considered as a bug from a certain point of view)
Would it make more sense to force 127.0.0.1 instead of gethostbyname? I can't think of a MySQL instance I've encountered that wasn't listening on localhost unless it was using only sockets. That would negate the need for the name resolution.
I agree with latest comment from @alafon: imho how it currently works is in fact correct. It is not necessarily up to the app to alter something which the underlying platform (php mysql libs) do - and is btw well documented on php.net. +1 for ""=system, "disabled"=try to force tcp-ip
The main problem here is that localhost could be aliased to other names as well. And 127...* is also the same thing as 127.0.0.1. Should we then catch usage of those as well? So we could maybe first figure out how the mysql client does the name resolution thing to be able to correctly prevent its automatic use-pipes-instead switch...