?
avatar GunnarBs
GunnarBs
21 Mar 2015

Steps to reproduce the issue

Performance only.

Install joomla on localhost. Set configuration.php public $host = 'localhost';
(This is a wamp server, default by xampp).
Turn on debug mode for server.

Open any page or administration page.

Expected result

Fast connection to db as this is localhost.

Note: solution provided below

Actual result

Connection time is > 1 second.

Time: 1.0 ms / 1.0 ms Memory: 0.652 MB / 0.65 MB Application: afterLoad
*** Time: 1187.1 ms / 1188.1 ms Memory: 3.930 MB / 4.58 MB Application: afterInitialise
Time: 23.0 ms / 1211.1 ms Memory: 0.345 MB / 4.93 MB Application: afterRoute

with provided fix:
Time: 159.0 ms / 160.0 ms Memory: 3.936 MB / 4.59 MB Application: afterInitialise

System information (as much as possible)

Additional comments

This can be changed easily in
/libraries/joomla/database/driver/mysqli.php
by using gethostbyname(..);

at around line 160
change:
$this->connection = @mysqli_connect(
$this->options['host'], $this->options['user'], $this->options['password'], null, $this->options['port'], $this->options['socket']
);

to:
$host = $this->options['host'] == 'localhost' ? gethostbyname($this->options['host']) : $this->options['host'];
$this->connection = @mysqli_connect(
$host, $this->options['user'], $this->options['password'], null, $this->options['port'], $this->options['socket']
);

avatar GunnarBs GunnarBs - open - 21 Mar 2015
avatar GunnarBs GunnarBs - change - 21 Mar 2015
Labels Removed: ?
avatar vdespa
vdespa - comment - 22 Mar 2015

This is a configuration problem, not a Joomla issue. What you are proposing is basically overriding the configuration set by the user. This is not acceptable, in my opinion.

Yes, MySQL can waste time while trying to resolve localhost. You can also add

127.0.0.1 localhost

to your hosts file to speed things up.

Thanks for your report.


This comment was created with the J!Tracker Application at issues.joomla.org/joomla-cms/6531.
avatar vdespa vdespa - change - 22 Mar 2015
Status New Closed - Unconfirmed Report
Closed_Date 0000-00-00 00:00:00 2015-03-22 14:43:27
Closed_By vdespa
avatar joomla-cms-bot joomla-cms-bot - change - 22 Mar 2015
Status New Closed
Closed_Date 0000-00-00 00:00:00 2015-03-22 14:43:27
avatar joomla-cms-bot joomla-cms-bot - close - 22 Mar 2015
avatar joomla-cms-bot
joomla-cms-bot - comment - 22 Mar 2015

Set to "closed" on behalf of @vdespa by The JTracker Application at issues.joomla.org/joomla-cms/6531

avatar joomla-cms-bot joomla-cms-bot - close - 22 Mar 2015
avatar zero-24 zero-24 - close - 22 Mar 2015
avatar GunnarBs
GunnarBs - comment - 3 Apr 2015

I am politly asking to reopen the issue.

Reasons:
a) The code was not understood.
This does not override the user configuration.
if localhost then host = gethostbyname( localhost) is nothing else than what mysql does.
b) changing the hosts file may be possible but is only understood by few. This is a very popular issue, see
http://stackoverflow.com/questions/13439817/why-is-my-mysqli-connection-so-slow/13439864#13439864

avatar mbabker
mbabker - comment - 3 Apr 2015

I have to agree on this being closed as a config issue. MySQL allows both localhost and 127.0.0.1 as valid host names and depending on your server configuration may result in different behaviors (i.e. a socket connection versus TCP/IP). Changing the code in Joomla to convert localhost to an IP address always could cause unintended side effects, including changing the manner in which the software connects to the database server.

Items like this should be managed through your local configuration.

avatar GunnarBs
GunnarBs - comment - 3 Apr 2015

Well, then we leave it as it is.

avatar fastslack
fastslack - comment - 3 Apr 2015

If you like to speed up your local mysql connection, you can use directly socket connection. Edit your configuration.php file and set:

    public $host = ':/var/run/mysql/mysql.sock';
avatar zero-24 zero-24 - change - 3 Apr 2015
Labels Added: ?

Add a Comment

Login with GitHub to post a comment