Pimcore\Db::close PHP Method

close() public static method

public static close ( ) : void
return void
    public static function close()
    {
        try {
            if (\Zend_Registry::isRegistered("Pimcore_Db")) {
                $db = \Zend_Registry::get("Pimcore_Db");
                if ($db instanceof Wrapper) {
                    // the following select causes an infinite loop (eg. when the connection is lost -> error handler)
                    //Logger::debug("closing mysql connection with ID: " . $db->fetchOne("SELECT CONNECTION_ID()"));
                    $db->closeResource();
                    $db->closeWriteResource();
                }
            }
        } catch (\Exception $e) {
            Logger::error($e);
        }
    }

Usage Example

示例#1
0
 /**
  * Forces a garbage collection.
  * @static
  * @return void
  */
 public static function collectGarbage($keepItems = array())
 {
     // close mysql-connection
     Db::close();
     $protectedItems = array("Zend_Locale", "Zend_View_Helper_Placeholder_Registry", "Zend_View_Helper_Doctype", "Zend_Translate", "Zend_Navigation", "Pimcore_API_Plugin_Broker", "pimcore_tag_block_current", "pimcore_tag_block_numeration", "Config_system", "pimcore_admin_user", "Config_website", "pimcore_editmode", "pimcore_error_document", "pimcore_site", "Pimcore_Db");
     if (is_array($keepItems) && count($keepItems) > 0) {
         $protectedItems = array_merge($protectedItems, $keepItems);
     }
     if (is_array(self::$globallyProtectedItems) && count(self::$globallyProtectedItems)) {
         $protectedItems = array_merge($protectedItems, self::$globallyProtectedItems);
     }
     $registryBackup = array();
     foreach ($protectedItems as $item) {
         if (\Zend_Registry::isRegistered($item)) {
             $registryBackup[$item] = \Zend_Registry::get($item);
         }
     }
     \Zend_Registry::_unsetInstance();
     foreach ($registryBackup as $key => $value) {
         \Zend_Registry::set($key, $value);
     }
     Db::reset();
     // force PHP garbage collector
     gc_enable();
     $collectedCycles = gc_collect_cycles();
     \Logger::debug("garbage collection finished, collected cycles: " . $collectedCycles);
 }