Bug #42977 [Nab]: localhost setting goes to socket instead of 127.0.0.1
| From: | ab@php.net | Date: | Wed, 16 Apr 2014 18:17:07 +0000 |
| Subject: | Bug #42977 [Nab]: localhost setting goes to socket instead of 127.0.0.1 | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-185289@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=42977&edit=1
ID: 42977
Updated by: ab@php.net
Reported by: marc at perkel dot com
Summary: localhost setting goes to socket instead of
127.0.0.1
Status: Not a bug
Type: Bug
Package: MySQL related
Operating System: linux
PHP Version: 5.2.4
Block user comment: N
Private report: N
New Comment:
This is something known for ages and documented well for the mysql commando. So PHP just reflects
what one already expects, no misleading at all. Please read more about this here http://dev.mysql.com/doc/refman/5.1/en/connecting.html
.
Previous Comments:
------------------------------------------------------------------------
[2014-04-16 16:58:50] rcmova at gmail dot com
I've been playing around with 'mod_ruid2' and found the same problem since socket is
not reachable from the jail.
PHP module will try to connect to mysql (unreachable) socket even if the specified host is
'localhost' ignoring actual 'my.cnf' config (since it's not even tried to
be read at this moment).
Problem will not be reproduced if you use '127.0.0.1' as connection host since a TCP
connection is used instead.
IMHO, that's a smart (socket should be faster) but misleading beahaviour.
I've been reading PHP source and found the logic here:
https://github.com/php/php-src/blob/master/ext/mysqlnd/mysqlnd.c#L920
An easy PoC to make a 'localhost' TCP connection is to modify that line of code to
'strncasecmp()' against, for example, 'local.host'.
This way module will use a TCP connection since it won't consider 'localhost' as
"use socket" mandatory.
I don't know if there are some other implications in this issue that justifies this behaviour
in the module, but my ideal workflow for it would be something like this:
* If 'localhost' is defined as connection host:
* Check wether 'my.cnf' defines a socket or not
* Check wether defined socket is reacheable or not and use it if it is
* Fallback to 127.0.0.1 if socket is not reacheable since that's the EXPLICITLY defined
connection host
I hope to read some thoughts about this issue at least, since it was reported back in 2007 and
it's still a big issue for many people around.
------------------------------------------------------------------------
[2007-10-17 09:29:41] johannes@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to
report
a bug at http://bugs.php.net/how-to-report.php
If you want to read settings from the my.cnf you have to use MySQLi and provide the option
MYSQLI_READ_DEFAULT_GROUP, ext/mysql is legacy code. (see also http://bugs.mysql.com/bug.php?id=31577 )
------------------------------------------------------------------------
[2007-10-15 17:14:41] marc at perkel dot com
Description:
------------
When a PHP application tries to call MySQL and it is set to talk to localhost it talks only to the
socket and not to TCP 127.0.0.1. In my.cnt I set the client as follows:
[client]
protocol=TCP
However that is ignored.
I'm running a web server hosting some 100 applications installed by many different people. So
changing all the localhost setting to 127.0.0.1 isn't practical. What I want to do is not use
the socket at /var/lib/mysql/mysql.sock at all. The reason is that I'm trying to mugrate all
mysql to a dedicated mysql server and having the web server talk to 127.0.0.1 and link them with an
SSH tunnel. In this setup there will be no socket.
I left a bug report at mysql.com and they blame the problem on PHP so i'm now here to let you
know about it.
Reproduce code:
---------------
Set configuration to localhost and disable socket and PHP can't talk to TCP 127.0.0.1
Expected result:
----------------
I expect PHP to ignore the unix socket and talk to TCP 127.0.0.1
Actual result:
--------------
No access
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=42977&edit=1