/** * Setup Test */ protected function setUp() { $hostname = $GLOBALS["hostname"]; $username = $GLOBALS["username"]; $password = $GLOBALS["password"]; $dbname = $GLOBALS["dbname"]; $this->db = MyDb::getInstance('MySQLDb', $hostname, $username, $password, $dbname, 3306); }
<?php require_once __DIR__ . '/include.php'; $db = MyDb::getInstance(); /** * Make sure all individual pings are running for all hosts */ $res = $db->query('SELECT * FROM hosts'); while ($hostData = $res->fetch_array()) { $pidFile = $_config['pidFilePath'] . '/' . $hostData['id']; // Check if we have fresh data for host $dataCheck = $db->fetchOne("SELECT time FROM `ping-result` WHERE host_id = {$hostData['id']} ORDER BY id DESC LIMIT 1"); if (time() - strtotime($dataCheck['time']) < 5) { // Fresh data, no need to do anything. Next host please! continue; } // Need to kill existing process, as it might have hung, or just cleanup PID file if (file_exists($pidFile) && file_exists("/proc/" . file_get_contents($pidFile))) { $pid = file_get_contents($pidFile); `kill -9 {$pid}`; } if (file_exists($pidFile)) { unlink($pidFile); } // Starting new thread for ping for this host $runFile = "nohup php " . __DIR__ . "/ping-host.php {$hostData['id']} > /dev/null 2> /dev/null </dev/null & "; `{$runFile}`; } /** * Consolidate every minute for ease of charting, and cleanup old data */
$dbname = 'ODBCDSN'; // ODBC Data Source Name $dbODBC = MyDb::getInstance($provider, $hostname, $username, $password, $dbname, 1); $query = sprintf("SELECT 1 AS %s", $dbODBC->escape($provider)); // Associate print_r($dbODBC->executeCommand($query)); // Enumerate print_r($dbODBC->executeCommand($query, null, MyDb::ENUM)); $dbODBC = null; // PostgreSQL Example $provider = 'PostgreSQLDb'; $hostname = ''; $username = ''; $password = ''; $dbname = ''; $dbPgSQL = MyDb::getInstance($provider, $hostname, $username, $password, $dbname, 5432); $query = sprintf("SELECT 1 AS %s", $dbPgSQL->escape($provider)); // Associate print_r($dbPgSQL->executeCommand($query)); // Enumerate print_r($dbPgSQL->executeCommand($query, null, MyDb::ENUM)); $dbPgSQL = null; // Mysql Singleton Example $provider = 'MySQLDb'; $hostname = ''; $username = ''; $password = ''; $dbname = ''; $db = MyDb::getConnection($provider, $hostname, $username, $password, $dbname, 3306); $query = sprintf("SELECT 1 AS %s", $dbMySQL->escape($provider)); // Associate