Skip to content

Commit fa8b451

Browse files
committed
Fix session locking
1 parent e8a0473 commit fa8b451

File tree

11 files changed

+33
-45
lines changed

11 files changed

+33
-45
lines changed

app.test/.env

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ CACHE_DRIVER=file
2020
FILESYSTEM_DRIVER=local
2121
QUEUE_CONNECTION=sync
2222
SESSION_DRIVER=file
23-
SESSION_LIFETIME=120
23+
SESSION_LIFETIME=1440
2424

2525
MEMCACHED_HOST=127.0.0.1
2626

app.test/app/Controllers/Auth/Farewell.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ class Farewell extends Controller implements ControllerInterface
99
{
1010
public function get()
1111
{
12-
session_destroy();
12+
session()->destroy();
1313

1414
echo $this->view('pages.auth.farewell');
1515
}

app.test/app/Controllers/Auth/Logout.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ class Logout extends Controller implements ControllerInterface
99
{
1010
public function get()
1111
{
12-
session_destroy();
12+
session()->destroy();
1313

1414
cookie('Strict')->del('uuid');
1515
cookie('Strict')->del('remember_token');

app.test/app/Controllers/Auth/ResetPassword.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public function post()
4747
$data['status'] = 'success';
4848
$data['message'] = 'Your password has been successfully changed.';
4949

50-
session_destroy();
50+
session()->destroy();
5151
}
5252
} else {
5353
$data['status'] = 'fail';

app.test/app/Controllers/Auth/Welcome.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ public function get()
1313
$userid = session()->get('userid');
1414
(new Users())->updateWelcomedById(1, $userid);
1515

16-
session_destroy();
16+
session()->destroy();
1717

1818
echo $this->view('pages.auth.welcome');
1919
}

app.test/app/Helpers/Session.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@ class Session
66
{
77
public function set(string $path, mixed $value = null, string $separator = '.'): void
88
{
9+
session_start();
910
Dot::set($_SESSION, $path, $value, $separator);
11+
session_write_close();
1012
}
1113

1214
public function get(string $path, string $separator = '.'): mixed
@@ -21,6 +23,15 @@ public function has(string $path, string $separator = '.'): bool
2123

2224
public function del(string $path, string $separator = '.'): void
2325
{
26+
session_start();
2427
Dot::del($_SESSION, $path, $separator);
28+
session_write_close();
29+
}
30+
31+
public function destroy(): void
32+
{
33+
session_start();
34+
session_unset();
35+
session_destroy();
2536
}
2637
}

app.test/app/Models/UserFaker.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public function createTable(): UserFaker
1919
{
2020
$this->pdo->exec(file_get_contents(SQL_PATH.'/createUsersTable.sql'));
2121

22-
session_destroy();
22+
session()->destroy();
2323

2424
echo "Created User Table.\n";
2525

@@ -30,7 +30,7 @@ public function dropTable(): UserFaker
3030
{
3131
$this->pdo->exec(file_get_contents(SQL_PATH.'/dropUsersTable.sql'));
3232

33-
session_destroy();
33+
session()->destroy();
3434

3535
echo "Dropped User Table.\n";
3636

app.test/app/helpers.php

Lines changed: 2 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ function bin2uuid4(string $binary = ''): string
4545
if (!function_exists('session')) {
4646
function session(): App\Helpers\Session
4747
{
48-
return new \App\Helpers\Session();
48+
return new \App\Helpers\Session;
4949
}
5050
}
5151

@@ -63,37 +63,9 @@ function mailer(): PHPMailer\PHPMailer\PHPMailer
6363
}
6464
}
6565

66-
if (!function_exists('str_random')) {
67-
function str_random(int $length = 10): string
68-
{
69-
return \App\Helpers\Str::random($length);
70-
}
71-
}
72-
73-
if (!function_exists('str_starts_with')) {
74-
function str_starts_with(string $haystack, string $needle): bool
75-
{
76-
return \App\Helpers\Str::str_starts_with($haystack, $needle);
77-
}
78-
}
79-
80-
if (!function_exists('str_ends_with')) {
81-
function str_ends_with(string $haystack, string $needle): bool
82-
{
83-
return \App\Helpers\Str::str_ends_with($haystack, $needle);
84-
}
85-
}
86-
87-
if (!function_exists('str_contains')) {
88-
function str_contains(string $haystack, string $needle): bool
89-
{
90-
return \App\Helpers\Str::str_contains($haystack, $needle);
91-
}
92-
}
93-
9466
if (!function_exists('substr_replace_offset')) {
9567
function substr_replace_offset(string $search, string $replace, int $start = 0, int|null $end = null): string
9668
{
9769
return \App\Helpers\Str::substr_replace_offset($search, $replace, $start, $end);
9870
}
99-
}
71+
}

app.test/config/session.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@
2828
|
2929
*/
3030

31-
'lifetime' => env('SESSION_LIFETIME', 120),
31+
'lifetime' => env('SESSION_LIFETIME', 1440),
32+
'expire' => env('SESSION_EXPIRE', 30),
3233

3334
/*
3435
|--------------------------------------------------------------------------

app.test/public/index.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@
88
ini_set('display_errors', 1);
99

1010
// Start The Application
11-
require_once __DIR__.'/../server.php';
11+
require_once __DIR__ . '/../server.php';
1212

1313
// Create Router instance
1414
$router = new \Bramus\Router\Router();
1515

1616
// Define routes
17-
(require_once __DIR__.'/../routes/web.php')($router);
17+
(require_once __DIR__ . '/../routes/web.php')($router);
1818

1919
// Run it!
20-
$router->run();
20+
$router->run();

0 commit comments

Comments
 (0)