Speed ​​up php :: PDO & # 8594; __

I used webgrind and xdebug to get rid of the performance of my site. 85% of the page load time is taken as the function php :: PDO → __ construct (about 1 second) ...

this is unacceptable. can I somehow optimize this function? (caching, mysql configuration, etc.)

I am using php, mysql and codeigniter with redbean. redbean uses the pdo build function ...

here is the source code of the function

/** 
 * Establishes a connection to the database using PHP PDO 
 * functionality. If a connection has already been established this 
 * method will simply return directly. This method also turns on 
 * UTF8 for the database and PDO-ERRMODE-EXCEPTION as well as 
 * PDO-FETCH-ASSOC. 
 * 
 * @return void 
 */ 
public function connect() { 
   if ($this->isConnected) return; 
    $user = $this->connectInfo['user']; 
    $pass = $this->connectInfo['pass']; 
    //PDO::MYSQL_ATTR_INIT_COMMAND 
     $this->pdo = new PDO( 
               $this->dsn, 
               $user, 
               $pass, 
               array(1002 => 'SET NAMES utf8', 
                          PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION, 
                          PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC, 

               ) 
     ); 
     $this->pdo->setAttribute(PDO::ATTR_STRINGIFY_FETCHES, true); 
     $this->isConnected = true; 
 } 
+5
source share
2 answers

The solution is quite simple ...

PDO connecting localhost -> 1 second

PDO connecting to 127.0.0.1 -> 50 miliseconds ...

dont aks me why ... something seems to be related to trying and waiting for ipv6 to connect and then returning to the old ipv4 ... the ipv4 address is not trying ipv6 ...

+7

PDO , ... . MySql , ? , mysql_connect ? Redbean, < 0.01s, ...

0

All Articles