Write and close session in `\MvcCore::Terminate();`.
Serialize all metadata and call php function to write session into php session storage.
(HDD, Redis, database, etc., depends on php configuration).
@return void
421098
public static function Close () {
		if (!static::GetStarted()) return;
		register_shutdown_function(function () {
			foreach (static::$instances as & $instance)
				if (count((array) $_SESSION[$instance->__name]) === 0)
					// if there is nothing in namespace - destroy it. It's useless.
					$instance->Destroy();
			$metaKey = static::SESSION_METADATA_KEY;
			$_SESSION[$metaKey] = serialize(static::$meta);
			@session_write_close();
		});
	}
812828
public function closeWriteAndReadAll()
    {
        $this->closeWrite();
        $response = $this->read();
        while (!is_null($response)) {
            yield $response;
            $response = $this->read();
        }
    }
337051
public function dispose() {
        parent::dispose(); // Call parent dispose to write/close session and other common stuff before closing connection

        if ($this->sqlsrv) {
            sqlsrv_close($this->sqlsrv);
            $this->sqlsrv = null;
        }
    }
643874
public function shutdown()
    {
        if ($this->is_prepared === true) {
            $this
                ->getSession()
                ->getConnection()
                ->executeAnonymousQuery(sprintf(
                    "deallocate %s",
                    $this->getSession()->getConnection()->escapeIdentifier($this->getClientIdentifier())
                ));

            $this->is_prepared = false;
        }
    }
295331
public function write(
        /*# string */ $session_id,
        /*# string */ $session_data
    )/*# : bool */ {
        $file = $this->getSessionFile($session_id);
        return $this->storage->put($file, $session_data);
    }
760326
private function write()
    {
        ftruncate($this->handle, 0);
        rewind($this->handle);

        fwrite($this->handle, serialize($this->data));
    }
113272
protected function prepareSessionData () {
		if ($_SESSION === NULL) return;

		// read `\MvcCore\Session` storage
		$sessionClass = \MvcCore\Application::GetInstance()->GetSessionClass();
		$sessionRawMetaStore = $sessionClass::GetSessionMetadata();
		$sessionMetaStore = $sessionRawMetaStore instanceof \stdClass
			? $sessionRawMetaStore
			: (object) ['names' => []];
		$maxLifeTimes = (object) [
			'hoops'		=> 0,
			'seconds'	=> 0,
		];

		$standardRecords = [];
		$namespaceRecords = [];

		// look for each record in `$_SESSION`
		// if data are defined as session namespace
		// record in `\MvcCore\Session` meta store:
		foreach ($_SESSION as $sessionKey => $sessionData) {
			if ($sessionKey === self::$MetaStoreKey) continue;
			$item = new \stdClass;
			$item->key = $sessionKey;
			$item->value = \Tracy\Dumper::toHtml($sessionData);
			if (isset($sessionMetaStore->names[$sessionKey])) {
				if (count((array) $_SESSION[$sessionKey]) === 0)
					// this will be destroyed automatically by
					// \MvcCore\Session::Close();` before `session_write_close()`.
					continue;
				$item->type = self::_TYPE_NAMESPACE;
				$item->expirations = [];
				if (isset($sessionMetaStore->hoops[$sessionKey])) {
					$value = $sessionMetaStore->hoops[$sessionKey];
					$item->expirations[] = (object) [
						'type'	=> self::_EXPIRATION_HOOPS,
						'value'	=> $value,
						'text'	=> $value . ' hoops',
					];
					if ($value > $maxLifeTimes->hoops)
						$maxLifeTimes->hoops = $value;
				}
				if (isset($sessionMetaStore->expirations[$sessionKey])) {
					$value = $sessionMetaStore->expirations[$sessionKey] - $this->now;
					$item->expirations[] = (object) [
						'type'	=> self::_EXPIRATION_TIME,
						'value'	=> $value,
						'text'	=> $this->_formateMaxLifeTimestamp($value),
					];
					if ($value > $maxLifeTimes->seconds)
						$maxLifeTimes->seconds = $value;
				}
				$namespaceRecords[$sessionKey] = $item;
			} else {
				$item->type = self::_TYPE_PHP;
				$standardRecords[$sessionKey] = $item;
			}
		}

		ksort($standardRecords);
		ksort($namespaceRecords);
		$this->session = array_merge($namespaceRecords, $standardRecords);

		$maxLifeTimesItems = [];
		if ($maxLifeTimes->seconds > 0)
			$maxLifeTimesItems[] = $this->_formateMaxLifeTimestamp($maxLifeTimes->seconds);
		if ($maxLifeTimes->hoops > 0)
			$maxLifeTimesItems[] = $maxLifeTimes->hoops . ' hoops';
		$this->sessionMaxLifeTime = implode(', ', $maxLifeTimesItems);
	}
1270820
static public function stop()
    {
        if ( !self::$hasStarted )
        {
             return false;
        }
        session_write_close();
        self::$hasStarted = false;
        self::$handlerInstance = null;
        return true;
    }
93334
public function close()
    {
        if ($this->gcCalled) {
            $this->gcCalled = false;

            // delete the session records that have expired
            $sql = "DELETE FROM $this->table WHERE $this->lifetimeCol + $this->timeCol < :time";

            $stmt = $this->db->query($sql)
                        ->bind(':time', time())
                        ->execute();
        }

        return true;
    }
1194880
public function onClose()
    {
        if ($this->realm !== null) {
            // only send the leave metaevent if we actually made it into the realm
            if ($this->isAuthenticated()) {
                // metaevent
                $this->getRealm()->publishMeta('wamp.metaevent.session.on_leave', [$this->getMetaInfo()]);
            }
            $this->dispatcher->dispatch('LeaveRealm', new LeaveRealmEvent($this->realm, $this));

            $this->realm = null;
        }
    }
360795
public function save()
    {
        $this->session['last_activity'] = time();

        // age it that should expire at the end of the user's next request.
        $this->age();

        $sessionConf = Config::get('session');

        // save data into the specialized storage.
        $this->storage->save($this->session, $sessionConf, $this->exists);

        // determine the owner of the session
        // on the user's subsequent requests to the application.
        $this->cookie($sessionConf);

        // calculate and run garbage collection cleaning.
        $cleaning = $sessionConf['garbage_collection'];

        if (mt_rand(1, $cleaning[1]) <= $cleaning[0]) {
            $this->clean();
        }
    }
195125
public function close()
    {
        $this->writeToLog('============================================', true);
        $this->writeToLog('Log Closed: ' . DateTimeObj::get('c'), true);
        $this->writeToLog("============================================" . PHP_EOL . PHP_EOL, true);
    }
1157086
private void closeSession(){
        if(LOGGER.isDebugEnabled()){
            LOGGER.debug("Close the session, sessionId=" + session.id + ", timeOut=" + session.timeOut);
        }
        if(! closing && getStatus().isConnected()){
            closing = true;
            if(getStatus().isAlive()){
                setStatus(ConnectionStatus.NOT_CONNECTED);
            }
            cleanupSession();
            closing = false;
        }
    }
733335
public function end() {
		$this->get = null;
		$this->post = null;
		$this->server = null;
		$this->header = null;
		$this->cookie = null;
		$this->files = null;
		$this->sw_request = null;
		if ($this->session !== null) {
			$handler = Container::getInstance()->get(Dispatcher::class)->getSessionHandler();
			$handler->write($this->session->id(), $this->session->encode());
			$this->session = null;
		}
	}
1053239
public function stream_close()
    {
        @fclose($this->temporaryFileHandle);
        
        // Upload the file?
        if ($this->writeMode) {
            // Make sure the container exists
            if (! $this->containerExists($this->fileName)) {
                $this->getStorageClient($this->fileName)->createContainer($this->getContainerName($this->fileName));
            }
            
            $mimeTypeGuesser = MimeTypeGuesser::getInstance();
            $createBlobOptions = new CreateBlobOptions();
            $createBlobOptions->setBlobContentType($mimeTypeGuesser->guess($this->temporaryFileName));
            
            // Upload the file
            try {
                $result = $this->getStorageClient($this->fileName)->createBlockBlob($this->getContainerName($this->fileName), $this->getFileName($this->fileName), fopen($this->temporaryFileName, "r"), $createBlobOptions);
            } catch (Exception $ex) {
                $this->cleanup();
                
                throw $ex;
            }
        }
        
        $this->cleanup();
    }
203480
public function close()
    {
        $writer = IOFactory::createWriter($this->phpExcelObject, 'Xlsx');
        //\PHPExcel_IOFactory::createWriter($this->phpExcelObject, 'Excel2007');
        $writer->save($this->filename);
    }
274137
public function destroy()
    {
        if ( NULL !== $this->sessionID )
        {
            session_write_close();
        }
        elseif ( NULL === $this->sessionID && $this->strict )
        {
            throw new InvalidSessionException( 'There is no session to close' );
        }
    }