CodeIgniter icon indicating copy to clipboard operation
CodeIgniter copied to clipboard

Codeigniter3 and session_gc

Open wadealer opened this issue 5 years ago • 2 comments

As as CI documentation says

Under CLI, the Session library will automatically halt itself, as this is a concept based entirely on the HTTP protocol.

But PHP documentations says:

Probability based GC works somewhat but it has few problems. 1) Low traffic sites' session data may not be deleted within the preferred duration. 2) High traffic sites' GC may be too frequent GC. 3) GC is performed on the user's request and the user will experience a GC delay. Therefore, it is recommended to execute GC periodically for production systems using, e.g., "cron" for UNIX-like systems. Make sure to disable probability based GC by setting session.gc_probability to 0.

And now we faced the probleam. We cann't use CRON because session class doesn't work with CLI. If we try to use anothe example from PHP docs:

// Need active session to initialize session data storage access.
session_start();

// Executes GC immediately
session_gc();

// Clean up session ID created by session_gc()
session_destroy();

it is do nothing, because handleers are not inited properly. Any ideas?

wadealer avatar Aug 25 '20 07:08 wadealer

Can you write that code inside a controller (like a webhook) and call it with wget within cron ?

[controller/Session.php] ... public function gc(){ //Do some sanity check first // Need active session to initialize session data storage access. session_start(); // Executes GC immediately session_gc(); // Clean up session ID created by session_gc() session_destroy(); }

[...]

[crontab]

          • wget "http://:/session/gc()" > /dev/null

[...]

on cron?

lemil avatar Oct 04 '20 22:10 lemil

Hello, I fork this to start solving this problem. I have a solution to this issue. It works done in my apps and websites.

I'll explain the steps of my work and the topic in a few days.

SolinSM avatar Nov 12 '20 17:11 SolinSM