Moodle PHP Documentation 4.5
Moodle 4.5dev (Build: 20240606) (d3ae1391abe)
core\session\database Class Reference

Database based session handler. More...

Inheritance diagram for core\session\database:
core\session\handler

Public Member Functions

 __construct ()
 Create new instance of handler.
 
 abort ()
 Release lock on the session without writing it.
 
 close ()
 Close session handler.
 
 destroy (string $id)
 Destroy session handler.
 
 gc (int $max_lifetime)
 GC session handler.
 
 init ()
 Init session handler.
 
 kill_all_sessions ()
 Kill all active sessions, the core sessions table is purged afterwards.
 
 kill_session ($sid)
 Kill one session, the session record is removed afterwards.
 
 open (string $path, string $name)
 Open session handler.
 
 read (string $sid)
 Read session handler.
 
 requires_write_lock ()
 Has this session been opened with a writelock? Your handler should call this during start() if you support read-only sessions.
 
 session_exists ($sid)
 Check the backend contains data for this session id.
 
 set_requires_write_lock ($requireswritelock)
 This is called after init() and before start() to indicate whether the session opened should be writable or not.
 
 start ()
 Start the session.
 
 write (string $id, string $data)
 Write session handler.
 
 write_close ()
 Write the session and release lock.
 

Protected Attributes

int $acquiretimeout = 120
 $acquiretimeout how long to wait for session lock
 
moodle_database $database = null
 $database session database
 
bool $failed = false
 $failed session read/init failed, do not write back to DB
 
string $lasthash = null
 $lasthash hash of the session data content
 
stdClass $recordid = null
 $record session record
 
boolean $requireswritelock = false
 $requireswritelock does the session need and/or have a lock?
 

Detailed Description

Database based session handler.

License
http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later

Member Function Documentation

◆ abort()

core\session\handler::abort ( )
inherited

Release lock on the session without writing it.

May not be possible in older versions of PHP. If so, session may be written anyway so that any locks are released.

◆ close()

core\session\database::close ( )

Close session handler.

{

See also
http://php.net/manual/en/function.session-set-save-handler.php}
Return values
boolsuccess

◆ destroy()

core\session\database::destroy ( string $id)

Destroy session handler.

{

See also
http://php.net/manual/en/function.session-set-save-handler.php}
Parameters
string$id
Return values
boolsuccess

◆ gc()

core\session\database::gc ( int $max_lifetime)

GC session handler.

{

See also
http://php.net/manual/en/function.session-set-save-handler.php}
Parameters
int$max_lifetimemoodle uses special timeout rules
Return values
boolsuccess

◆ init()

core\session\database::init ( )

Init session handler.

Reimplemented from core\session\handler.

◆ kill_all_sessions()

core\session\database::kill_all_sessions ( )

Kill all active sessions, the core sessions table is purged afterwards.

Reimplemented from core\session\handler.

◆ kill_session()

core\session\database::kill_session ( $sid)

Kill one session, the session record is removed afterwards.

Parameters
string$sid

Reimplemented from core\session\handler.

◆ open()

core\session\database::open ( string $path,
string $name )

Open session handler.

{

See also
http://php.net/manual/en/function.session-set-save-handler.php}
Parameters
string$path
string$name
Return values
boolsuccess

◆ read()

core\session\database::read ( string $sid)

Read session handler.

{

See also
http://php.net/manual/en/function.session-set-save-handler.php}
Parameters
string$sid
Return values
string|false

◆ requires_write_lock()

core\session\handler::requires_write_lock ( )
inherited

Has this session been opened with a writelock? Your handler should call this during start() if you support read-only sessions.

Return values
booltrue if session is intended to have a write lock.

◆ session_exists()

core\session\database::session_exists ( $sid)

Check the backend contains data for this session id.

Note: this is intended to be called from manager\session_exists() only.

Parameters
string$sid
Return values
booltrue if session found.

Reimplemented from core\session\handler.

◆ set_requires_write_lock()

core\session\handler::set_requires_write_lock ( $requireswritelock)
inherited

This is called after init() and before start() to indicate whether the session opened should be writable or not.

This is intentionally captured even if your handler doesn't support non-locking sessions, so that behavior (upon session close) matches closely between handlers.

Parameters
bool$requireswritelocktrue if needs to be open for writing

◆ start()

core\session\handler::start ( )
inherited

Start the session.

Return values
boolsuccess

Reimplemented in core\session\memcached, and core\session\redis.

◆ write()

core\session\database::write ( string $id,
string $data )

Write session handler.

{

See also
http://php.net/manual/en/function.session-set-save-handler.php}

NOTE: Do not write to output or throw any exceptions! Hopefully the next page is going to display nice error or it recovers...

Parameters
string$id
string$data
Return values
boolsuccess

◆ write_close()

core\session\handler::write_close ( )
inherited

Write the session and release lock.

If the session was not intentionally opened with a write lock, then we will abort the session instead if able.


The documentation for this class was generated from the following file: