Skip to main content
Github

Session

Sessions allow you to store user information across multiple requests.

The difference from session_start() is that blocking only occurs during read, write and regeneration, making it a little more flexible, and it can also write data after the headers have been sent.

Create a session

use Inphinit\Session; $session = new Session('session'); echo 'Session ID: ', $session->getId(), '<br>'; echo '<h2>Before:</h2>'; echo '<pre>'; var_dump($session->float); var_dump($session->int); var_dump($session->octal); echo '</pre>'; $session->float = microtime(true); $session->int = time(); $session->octal = 0666; echo '<h2>After:</h2>'; echo '<pre>'; var_dump($session->float); var_dump($session->int); var_dump($session->octal); echo '</pre>'; $session->commit();

Removing inactive session files

The APP_SESSION_MAX_INACTIVE environment variable is used to define the timeframe after which a session file is considered inactive. However, this process does not happen automatically; to clean up inactive session files, you can use the run session:clear command.

On Windows, run:

run session:clear

On other systems, run:

./run session:clear

Alternatively, using the PHP executable works on any operating system:

php run session:clear

Scheduling automatic cleanup

You can automate the cleanup process using the Task Scheduler, by adding something like this to the system/console.php file:

// Get the built-in command $command = $console->getCommand('session:clear'); if ($command !== null) { // Schedule the command to run every Sunday at 04:00 AM (UTC) $scheduler->command('session_clear_task', $command, [])->cron(0, 4, '*', '*', 0); }