Skip to content

Instantly share code, notes, and snippets.

@Majkl578
Last active August 29, 2015 14:08
Show Gist options
  • Save Majkl578/904927f5b5aa8f805abc to your computer and use it in GitHub Desktop.
Save Majkl578/904927f5b5aa8f805abc to your computer and use it in GitHub Desktop.
Nette sessions + custom save path and automatic GC, IT WORKS
{
"require": {
"nette/http": "2.2.*"
}
}
#!/bin/bash
run() {
ab -n $1 -c $2 http://local/sessions-test/test.php > /dev/null
}
files() {
echo `ls -1 data/ | wc -l`
}
run 100 20
files
sleep 2
run 100 20
files
sleep 2
run 100 20
files
sleep 2
run 100 20
files
sleep 5
run 1 1
files
<?php
require __DIR__ . '/vendor/autoload.php';
//$before = iterator_to_array(new FilesystemIterator(__DIR__ . '/data', FilesystemIterator::CURRENT_AS_PATHNAME | FilesystemIterator::SKIP_DOTS));
$session = new Nette\Http\Session((new Nette\Http\RequestFactory)->createHttpRequest(), new Nette\Http\Response());
$session->setName('blablasesstest');
$session->setSavePath(__DIR__ . '/data');
$session->setExpiration('+ 3 seconds');
$session->setOptions([
'gc_probability' => 100,
'gc_divisor' => '100',
]);
$session->start();
$session->getSection('test')->foo = 'bar';
$session->close();
//$after = iterator_to_array(new FilesystemIterator(__DIR__ . '/data', FilesystemIterator::CURRENT_AS_PATHNAME | FilesystemIterator::SKIP_DOTS));
//echo 'Before:', PHP_EOL;
//var_dump($before);
//echo 'After:', PHP_EOL;
//var_dump($after);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment