Note: You are currently viewing documentation for Moodle 3.1. Up-to-date documentation for the latest stable version of Moodle is probably available here: Sessions FAQ.

Sessions FAQ: Difference between revisions

From MoodleDocs
(see also heading)
 
(5 intermediate revisions by 4 users not shown)
Line 1: Line 1:
{{Managing a Moodle site}}
== What is the purpose of Sessions? ==
== What is the purpose of Sessions? ==
Web applications are "stateless". That is, by nature, any information stored in program variables is lost each time a script completes. That happens on every page. So for anything other than completely trivial scripts you need to have a way of storing information for that user for the current login. There's various ways to do this but the simplest is an implementation of PHP's native $_SESSION[] array that will keep information for a particular user on the same PC for a short period of time.
Web applications are "stateless". That is, by nature, any information stored in program variables is lost each time a script completes. That happens on every page. So for anything other than completely trivial scripts you need to have a way of storing information for that user for the current login. There are various ways to do this but the simplest is an implementation of PHP's native $_SESSION[] array that will keep information for a particular user on the same PC for a short period of time.


== What information do they hold?==
== What information do they hold?==
Line 6: Line 7:


== How are they constructed? ==
== How are they constructed? ==
It's a PHP thing. It's very simple. Moodle issues the session_start() 'command' and then access PHP's $_SESSION variable. The contents of that automagically persist in a written file.
It's a PHP thing. It's very simple. Moodle issues the session_start() 'command' and then access PHP's $_SESSION variable. The contents of that automagically persist in a written file/database/memcached/redis server.


== How long should they be retained for? ==
== How long should they be retained for? ==
Line 20: Line 21:
=== How do I delete them? ===
=== How do I delete them? ===
It's not very elegant, but at quiet times you can simply delete the sessions directory in moodledata. The worst that will happen is that anyone logged in gets thrown off. A slightly more elegant solution would delete any files in that directory more than a few hours old.
It's not very elegant, but at quiet times you can simply delete the sessions directory in moodledata. The worst that will happen is that anyone logged in gets thrown off. A slightly more elegant solution would delete any files in that directory more than a few hours old.
==Any further questions?==
Please post in the [https://moodle.org/mod/forum/view.php?id=596 Hardware and performance forum] on moodle.org.


==See also==
==See also==
Line 26: Line 31:


[[Category:FAQ]]
[[Category:FAQ]]
[[de:Sitzungen FAQ]]

Latest revision as of 06:36, 12 August 2017

What is the purpose of Sessions?

Web applications are "stateless". That is, by nature, any information stored in program variables is lost each time a script completes. That happens on every page. So for anything other than completely trivial scripts you need to have a way of storing information for that user for the current login. There are various ways to do this but the simplest is an implementation of PHP's native $_SESSION[] array that will keep information for a particular user on the same PC for a short period of time.

What information do they hold?

Sessions hold a range of information. The fact that you are logged on, your user profile, etc. Anything that needs to be available on all Moodle pages quickly.

How are they constructed?

It's a PHP thing. It's very simple. Moodle issues the session_start() 'command' and then access PHP's $_SESSION variable. The contents of that automagically persist in a written file/database/memcached/redis server.

How long should they be retained for?

There is no reason to keep them beyond the current, well, session.

Do I need to include them in my site backups?

No, not at all. The information required is for the immediate purposes of Moodle and is not required beyond that.

Do I need to delete them?

Session files should automatically be deleted when they are no longer needed. If files are building up you should look into why.

How do I delete them?

It's not very elegant, but at quiet times you can simply delete the sessions directory in moodledata. The worst that will happen is that anyone logged in gets thrown off. A slightly more elegant solution would delete any files in that directory more than a few hours old.

Any further questions?

Please post in the Hardware and performance forum on moodle.org.

See also