|
|
@ -3,13 +3,18 @@ |
|
|
|
class MySQL { |
|
|
|
class MySQL { |
|
|
|
|
|
|
|
|
|
|
|
private PDO $_db; |
|
|
|
private PDO $_db; |
|
|
|
|
|
|
|
private Memcached $_memcached; |
|
|
|
|
|
|
|
|
|
|
|
public function __construct(string $host, int $port, string $database, string $username, string $password) { |
|
|
|
public function __construct(string $host, int $port, string $database, string $username, string $password, Memcached $memcached = null) { |
|
|
|
|
|
|
|
|
|
|
|
$this->_db = new PDO('mysql:dbname=' . $database . ';host=' . $host . ';port=' . $port . ';charset=utf8', $username, $password, [PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8']); |
|
|
|
$this->_db = new PDO('mysql:dbname=' . $database . ';host=' . $host . ';port=' . $port . ';charset=utf8', $username, $password, [PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8']); |
|
|
|
$this->_db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); |
|
|
|
$this->_db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); |
|
|
|
$this->_db->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_OBJ); |
|
|
|
$this->_db->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_OBJ); |
|
|
|
$this->_db->setAttribute(PDO::ATTR_TIMEOUT, 600); |
|
|
|
$this->_db->setAttribute(PDO::ATTR_TIMEOUT, 600); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if ($memcached) { |
|
|
|
|
|
|
|
$this->_memcached = $memcached; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// System |
|
|
|
// System |
|
|
@ -86,6 +91,14 @@ class MySQL { |
|
|
|
|
|
|
|
|
|
|
|
public function getTopHostPages() { |
|
|
|
public function getTopHostPages() { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if ($this->_memcached) { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if ($result = $this->_memcached->get('MySQL.getTopHostPages')) { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return $result; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
$query = $this->_db->query(" SELECT |
|
|
|
$query = $this->_db->query(" SELECT |
|
|
|
|
|
|
|
|
|
|
|
`hostPageTarget`.`hostId`, |
|
|
|
`hostPageTarget`.`hostId`, |
|
|
@ -96,18 +109,6 @@ class MySQL { |
|
|
|
`hostTarget`.`name`, |
|
|
|
`hostTarget`.`name`, |
|
|
|
`hostTarget`.`port`, |
|
|
|
`hostTarget`.`port`, |
|
|
|
|
|
|
|
|
|
|
|
( |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
SELECT COUNT(*) FROM `hostPage` AS `hostPageTotal` |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
WHERE `hostPageTotal`.`hostId` = `hostPageTarget`.`hostId` |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
AND `hostPageTotal`.`httpCode` = 200 |
|
|
|
|
|
|
|
AND `hostPageTotal`.`timeBanned` IS NULL |
|
|
|
|
|
|
|
AND `hostPageTotal`.`mime` IS NOT NULL |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
) AS `total`, |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
( |
|
|
|
( |
|
|
|
|
|
|
|
|
|
|
|
SELECT COUNT(*) |
|
|
|
SELECT COUNT(*) |
|
|
@ -136,7 +137,14 @@ class MySQL { |
|
|
|
|
|
|
|
|
|
|
|
"); |
|
|
|
"); |
|
|
|
|
|
|
|
|
|
|
|
return $query->fetchAll(); |
|
|
|
$result = $query->fetchAll(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if ($this->_memcached) { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$this->_memcached->set('MySQL.getTopHostPages', $result, time() + 3600); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return $result; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public function getHosts() { |
|
|
|
public function getHosts() { |
|
|
@ -225,6 +233,36 @@ class MySQL { |
|
|
|
return $query->fetch()->total; |
|
|
|
return $query->fetch()->total; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public function getTotalHostPagesIndexed(int $hostId) { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if ($this->_memcached) { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if ($result = $this->_memcached->get(sprintf('MySQL.getTotalHostPagesIndexed.%s', $hostId))) { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return $result; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$query = $this->_db->prepare('SELECT COUNT(*) AS `total` FROM `hostPage` |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
WHERE `hostId` = ? |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
AND `httpCode` = 200 |
|
|
|
|
|
|
|
AND `timeBanned` IS NULL |
|
|
|
|
|
|
|
AND `mime` IS NOT NULL'); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$query->execute([$hostId]); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$result = $query->fetch()->total; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if ($this->_memcached) { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$this->_memcached->set(sprintf('MySQL.getTotalHostPagesIndexed.%s', $hostId), $result, time() + 3600); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return $result; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/* not in use |
|
|
|
/* not in use |
|
|
|
public function getTotalPagesByHttpCode(mixed $httpCode) { |
|
|
|
public function getTotalPagesByHttpCode(mixed $httpCode) { |
|
|
|
|
|
|
|
|
|
|
|