[DAEMONS] Move resetDb to the Daemon class
As it is used inside the Daemon class now, it should always be available.
This commit is contained in:
parent
344db5dcdf
commit
3460c13535
@ -41,6 +41,41 @@ class Daemon
|
||||
$this->_id = $id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Reconnect to the database for each child process,
|
||||
* or they'll get very confused trying to use the
|
||||
* same socket.
|
||||
*/
|
||||
protected function resetDb()
|
||||
{
|
||||
global $_DB_DATAOBJECT;
|
||||
|
||||
// Can't be called statically
|
||||
$user = new User();
|
||||
$conn = $user->getDatabaseConnection();
|
||||
$conn->disconnect();
|
||||
|
||||
// Remove the disconnected connection from the list
|
||||
foreach ($_DB_DATAOBJECT['CONNECTIONS'] as $k => $v) {
|
||||
if ($v === $conn) {
|
||||
unset($_DB_DATAOBJECT['CONNECTIONS'][$k]);
|
||||
}
|
||||
}
|
||||
|
||||
// Reconnect main memcached, or threads will stomp on
|
||||
// each other and corrupt their requests.
|
||||
$cache = Cache::instance();
|
||||
if ($cache) {
|
||||
$cache->reconnect();
|
||||
}
|
||||
|
||||
// Also reconnect memcached for status_network table.
|
||||
if (!empty(Status_network::$cache)) {
|
||||
Status_network::$cache->close();
|
||||
Status_network::$cache = null;
|
||||
}
|
||||
}
|
||||
|
||||
public function background()
|
||||
{
|
||||
// Database connection will likely get lost after forking
|
||||
|
@ -189,41 +189,6 @@ abstract class SpawningDaemon extends Daemon
|
||||
exit($exitCode);
|
||||
}
|
||||
|
||||
/**
|
||||
* Reconnect to the database for each child process,
|
||||
* or they'll get very confused trying to use the
|
||||
* same socket.
|
||||
*/
|
||||
protected function resetDb()
|
||||
{
|
||||
global $_DB_DATAOBJECT;
|
||||
|
||||
// Can't be called statically
|
||||
$user = new User();
|
||||
$conn = $user->getDatabaseConnection();
|
||||
$conn->disconnect();
|
||||
|
||||
// Remove the disconnected connection from the list
|
||||
foreach ($_DB_DATAOBJECT['CONNECTIONS'] as $k => $v) {
|
||||
if ($v === $conn) {
|
||||
unset($_DB_DATAOBJECT['CONNECTIONS'][$k]);
|
||||
}
|
||||
}
|
||||
|
||||
// Reconnect main memcached, or threads will stomp on
|
||||
// each other and corrupt their requests.
|
||||
$cache = Cache::instance();
|
||||
if ($cache) {
|
||||
$cache->reconnect();
|
||||
}
|
||||
|
||||
// Also reconnect memcached for status_network table.
|
||||
if (!empty(Status_network::$cache)) {
|
||||
Status_network::$cache->close();
|
||||
Status_network::$cache = null;
|
||||
}
|
||||
}
|
||||
|
||||
public function log($level, $msg)
|
||||
{
|
||||
common_log($level, get_class($this) . ' ('. $this->get_id() .'): '.$msg);
|
||||
|
Loading…
Reference in New Issue
Block a user