示例#1
0
 /**
  * Checks whether the server is up and running (accepting connections).
  * Will return true/false based on the server status.
  *
  * @return bool Returns true if server is running, false if not.
  * @access public
  */
 public function isUp()
 {
     $addr = $this->config->getAddress();
     $port = $this->config->getPort();
     $sock = @fsockopen($addr, $port, $errno, $errstr, (int) Flux::config('ServerStatusTimeout'));
     if (is_resource($sock)) {
         fclose($sock);
         return true;
     } else {
         return false;
     }
 }
示例#2
0
 /**
  * Establish connection to server based on config.
  *
  * @param Flux_Config $dbConfig
  * @return PDO
  * @access private
  */
 private function connect(Flux_Config $dbConfig)
 {
     $dsn = 'mysql:';
     // Differentiate between a socket-type connection or an ip:port
     // connection.
     if ($sock = $dbConfig->getSocket()) {
         $dsn .= "unix_socket={$sock}";
     } else {
         $dsn .= 'host=' . $dbConfig->getHostname();
         if ($port = $dbConfig->getPort()) {
             $dsn .= ";port={$port}";
         }
     }
     // May or may not have a database name specified.
     if ($dbName = $dbConfig->getDatabase()) {
         $dsn .= ";dbname={$dbName}";
     }
     $persistent = array(PDO::ATTR_PERSISTENT => (bool) $dbConfig->getPersistent());
     return new PDO($dsn, $dbConfig->getUsername(), $dbConfig->getPassword(), $persistent);
 }