Skip to content

Commit

Permalink
Merge pull request #7116 from kenjis/fix-docs-sessions
Browse files Browse the repository at this point in the history
docs: fix sessions.rst
  • Loading branch information
kenjis authored Jan 14, 2023
2 parents e30f5ee + 4f4e2f0 commit e5f321f
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 11 deletions.
31 changes: 20 additions & 11 deletions user_guide_src/source/libraries/sessions.rst
Original file line number Diff line number Diff line change
Expand Up @@ -525,6 +525,14 @@ into using `tmpfs <https://eddmann.com/posts/storing-php-sessions-file-caches-in
DatabaseHandler Driver
======================

.. important:: Only MySQL and PostgreSQL databases are officially
supported, due to lack of advisory locking mechanisms on other
platforms. Using sessions without locks can cause all sorts of
problems, especially with heavy usage of AJAX, and we will not
support such cases. Use ``session_write_close()`` after you've
done processing session data if you're having performance
issues.

The 'DatabaseHandler' driver uses a relational database such as MySQL or
PostgreSQL to store sessions. This is a popular choice among many users,
because it allows the developer easy access to the session data within
Expand All @@ -534,6 +542,9 @@ However, there are some conditions that must be met:

- You can NOT use a persistent connection.

Configure DatabaseHandler
-------------------------

In order to use the 'DatabaseHandler' session driver, you must also create this
table that we already mentioned and then set it as your
``$savePath`` value.
Expand Down Expand Up @@ -569,7 +580,7 @@ For PostgreSQL::
and the session ID and a delimiter. It should be increased as needed, for example,
when using long session IDs.

You will also need to add a PRIMARY KEY **depending on your 'sessionMatchIP'
You will also need to add a PRIMARY KEY **depending on your $matchIP
setting**. The examples below work both on MySQL and PostgreSQL::

// When sessionMatchIP = true
Expand All @@ -592,17 +603,9 @@ from the cli to generate a migration file for you::
> php spark make:migration --session
> php spark migrate

This command will take the **savePath** and **matchIP** settings into account
This command will take the ``$savePath`` and ``$matchIP`` settings into account
when it generates the code.

.. important:: Only MySQL and PostgreSQL databases are officially
supported, due to lack of advisory locking mechanisms on other
platforms. Using sessions without locks can cause all sorts of
problems, especially with heavy usage of AJAX, and we will not
support such cases. Use ``session_write_close()`` after you've
done processing session data if you're having performance
issues.

.. _sessions-redishandler-driver:

RedisHandler Driver
Expand All @@ -623,6 +626,9 @@ bundled with PHP.
Chances are, you're only be using the RedisHandler driver only if you're already
both familiar with Redis and using it for other purposes.

Configure RedisHandler
----------------------

Just as with the 'FileHandler' and 'DatabaseHandler' drivers, you must also configure
the storage location for your sessions via the
``$savePath`` setting.
Expand All @@ -632,7 +638,7 @@ link you to it:

https://github.com/phpredis/phpredis

.. warning:: CodeIgniter's Session library does NOT use the actual 'redis'
.. important:::: CodeIgniter's Session library does NOT use the actual 'redis'
``session.save_handler``. Take note **only** of the path format in
the link above.
Expand Down Expand Up @@ -665,6 +671,9 @@ deleted after Y seconds have passed (but not necessarily that it won't
expire earlier than that time). This happens very rarely, but should be
considered as it may result in loss of sessions.

Configure RedisHandler
----------------------

The ``$savePath`` format is fairly straightforward here,
being just a ``host:port`` pair:

Expand Down
2 changes: 2 additions & 0 deletions user_guide_src/source/libraries/sessions/039.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ class Session extends BaseConfig
{
// ...
public string $driver = 'CodeIgniter\Session\Handlers\DatabaseHandler';

// ...
public string $savePath = 'ci_sessions';

// ...
}
2 changes: 2 additions & 0 deletions user_guide_src/source/libraries/sessions/041.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ class Session extends BaseConfig
{
// ...
public string $driver = 'CodeIgniter\Session\Handlers\RedisHandler';

// ...
public string $savePath = 'tcp://localhost:6379';

// ...
}
2 changes: 2 additions & 0 deletions user_guide_src/source/libraries/sessions/042.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ class Session extends BaseConfig
{
// ...
public string $driver = 'CodeIgniter\Session\Handlers\MemcachedHandler';

// ...
public string $savePath = 'localhost:11211';

// ...
}

0 comments on commit e5f321f

Please sign in to comment.