criostage Posted December 18, 2013 Share Posted December 18, 2013 Hello all, this is just one of those questions that i think that have an rather quick awnser. I m concerned about the PDO connection i made witch takes some time to stablish, i was using an self made class where dynamicly i create the dsn get the values etc etc .. when i stabilish the connection takes up to 1.5 seconds to finish (where without the line that makes the connection takes 0.01s for the script to finish), so i tested out with just these 4 lines of code and i get the same result as my class. $dsn = 'mysql:host=localhost;port=3306;dbname=MyDatabase;charset=UTF8'; $username = 'root'; $passwd = ''; $sqlhandler = new PDO($dsn, $username, $passwd); The code i m using to mesure the the finish time (i found this in the php website): function convert($size){ $unit=array('b','kb','mb','gb','tb','pb'); return @round($size/pow(1024,($i=floor(log($size,1024)))),2).' '.$unit[$i]; } echo '<b>Memory used</b>: '. convert(memory_get_usage(true)).'<br>'; My "development" Enviroment is Windows 8.1 with EasyPHP 13.1 Dev Server (with PHP 5.5). My question is it's normal that just the connection takes this much to get completed? Thanks in advance Quote Link to comment Share on other sites More sharing options...
Solution Ch0cu3r Posted December 18, 2013 Solution Share Posted December 18, 2013 (edited) Does it improve if you use 127.0.0.1 instead of (localhost $dsn = 'mysql:host=127.0.0.1;port=3306;dbname=MyDatabase;charset=UTF8'; The code i m using to mesure the the finish time (i found this in the php website): That code has got nothing to do with how long the script took to execute. It returns the memory usage. You should not be using this to determine how long your script took to execute. EDIT: To time script execution you'll want to use something like the examples here Edited December 18, 2013 by Ch0cu3r Quote Link to comment Share on other sites More sharing options...
criostage Posted December 18, 2013 Author Share Posted December 18, 2013 Does it improve if you use 127.0.0.1 instead of (localhost $dsn = 'mysql:host=127.0.0.1;port=3306;dbname=MyDatabase;charset=UTF8'; That code has got nothing to do with how long the script took to execute. It returns the memory usage. You should not be using this to determine how long your script took to execute. EDIT: To time script execution you'll want to use something like the examples here hi, i dont know what to say but wierdly enough ... it does help, the connection is nearly instant using 127.0.0.1. In terms of networking i know localhost is the same as 127.0.0.1, do you mind explaining why with localhost takes 'way longer'? The reason why i m asking is mainly for self study ... and tyvm for your reply, i will mark as solved if anyone can explain me ... Quote Link to comment Share on other sites More sharing options...
Ch0cu3r Posted December 18, 2013 Share Posted December 18, 2013 (edited) It is a domain resolution problem. Computers need to convert a domain name into an address in order to now where the device is located. The domain resolution is done via DNS this is what could be causing the delay. Edited December 18, 2013 by Ch0cu3r Quote Link to comment Share on other sites More sharing options...
AbraCadaver Posted December 18, 2013 Share Posted December 18, 2013 IPv6 enabled Windows, such as Windows 8 resolve localhost to an IPV6 address ::1. If your application is not IPV6 then the connection must timeout and then the IPV4 address 127.0.0.1 is resolved and used. Quote Link to comment Share on other sites More sharing options...
jazzman1 Posted December 18, 2013 Share Posted December 18, 2013 IPv6 enabled Windows, such as Windows 8 resolve localhost to an IPV6 address ::1. If your application is not IPV6 then the connection must timeout and then the IPV4 address 127.0.0.1 is resolved and used. He should bind this IPv6 to the mysql server conf file as well to be able to use it. Here is a part of mine db server: ( mysql 5.5/ CentOS 6.4) [mysqld] datadir=/var/lib/mysql socket=/var/lib/mysql/mysql.sock bind-address = :: // connection [lxc@lxc1 ~]$ mysql -h ::1 -u lxc -ppassword --port=3306 Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 3 Server version: 5.5.35 MySQL Community Server (GPL) by Remi Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql> Quote Link to comment Share on other sites More sharing options...
AbraCadaver Posted December 18, 2013 Share Posted December 18, 2013 He should bind this IPv6 to the mysql server conf file as well to be able to use it. Here is a part of mine db server: ( mysql 5.5/ CentOS 6.4) Good idea! Quote Link to comment Share on other sites More sharing options...
criostage Posted December 19, 2013 Author Share Posted December 19, 2013 Wow tyvm guys this have been very usefull, i always look foward to keep learning Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.