开发者

mysql_connect "bool $new_link = true" is very slow

I'm using latest version of Xampp on 64bit Win7. The problem is that, when I use mysql_connect with "bool $new_link" set to true like so:

mysql_connect('localhost', 'root', 'my_password', TRUE);

script execution time increases dramatically (about 0,5 seconds per connection, and when I have 4 diffirent objects using different connections, it takes ~2 seconds).

Is setting "bool $new_link" to true, generally a bad idea or could it just be some problem with my so开发者_Python百科ftware configuration.

Thank you.

//Edit: I'm using new link, because I have multiple objects, that use mysql connections (new objects can be created inside already existing objects and so on). In the end, when it comes to unsetting objects (I have mysql_close inside my __destruct() functions), I figured, that the only way to correctly clean up loose ends would be that all objects have their own connection variables. I just formated my PC so configuration should be default conf.


Don't open a new connection unless you have a need for one (for instance, accessing multiple databases simultaneously).

Also you don't have to explicitly call mysql_close. I usually just include a function to quickly retrieve an existing db link (or a new one if none exists yet).

function &getDBConn() {
    global $DBConn;
    if(!$DBConn) $DBConn = mysql_connect(...);
    return $DBConn;
}
// now you can just call $dbconn = getDBConn(); whenever you need it


Use "127.0.0.1" instead of "localhost". It improved my performance with mysql_connect from ~1 sek to a couple of milliseconds.

Article about php/mysql_connect and IPv6 on windows: http://www.bluetopazgames.com/uncategorized/php-mysql_connect-is-slow-1-second-for-localhost-windows-7/

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜