Skip to content

Commit 65168fe

Browse files
committed
Add background ajax query in an attempt to prevent session timeout
1 parent ba9442e commit 65168fe

File tree

3 files changed

+27
-0
lines changed

3 files changed

+27
-0
lines changed

footer.php

+1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
<script src="plugins/tinymce/tinymce.min.js" referrerpolicy="origin"></script>
2525
<script src="plugins/Show-Hide-Passwords-Bootstrap-4/bootstrap-show-password.min.js"></script>
2626
<script src="plugins/clipboardjs/clipboard.min.js"></script>
27+
<script src="js/keepalive.js"></script>
2728

2829
<!-- AdminLTE App -->
2930
<script src="dist/js/adminlte.min.js"></script>

js/keepalive.js

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// Keep PHP sessions alive
2+
// Sends requests to keepalive.php in the background every 10 mins to prevent PHP garbage collection ending sessions
3+
4+
function keep_alive() {
5+
6+
//Send a GET request to keepalive.php as keepalive.php?keepalive
7+
jQuery.get(
8+
"keepalive.php",
9+
{keepalive: 'true'},
10+
function(data) {
11+
// Don't care about a response
12+
}
13+
);
14+
15+
}
16+
17+
// Run every 10 mins
18+
setInterval(keep_alive, 600000);

keepalive.php

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?php
2+
3+
// Keep PHP sessions alive
4+
// Receives requests via AJAX in the background every 10 mins to prevent PHP garbage collection ending sessions
5+
// See footer.php & js/keepalive.js
6+
7+
session_start();
8+
session_write_close();

0 commit comments

Comments
 (0)