Do not use the CI 4 session library |
Today I have the PHP Session with Redis configuration, with fallback, name configuration, etc., all defined in my php.ini file, however in CI4 I cannot use PHP's native session_start() to create my sessions.
In CodeIgniter 3 I could just remove it from autoload and that's it, but now it's not possible. Every time I try to use session_start() this message appears. Suggesting that CodeIgniter automatically initialized the session. Something I don't want. Code: ini_set(): Session ini settings cannot be changed when a session is active If I execute the session()->close(); below before session_start(), another error appears. Code: ini_set(): Session ini settings cannot be changed when a session is active How can I focus on using only session_start(), even though I know it is more archaic.
It is the following code:
https://github.com/codeigniter4/CodeIgni...1068-L1074 Extend the CodeIgniter class and override the storePreviousURL() method. See https://codeigniter4.github.io/CodeIgnit...asses.html (03-25-2024, 07:14 AM)ElTomTom Wrote: Today I have the PHP Session with Redis configuration, with fallback, name configuration, etc., all defined in my php.ini file, however in CI4 I cannot use PHP's native session_start() to create my sessions. Just out of curiosity, because I use PHP session settings geared for Redis too, what is it with CI4 sessions that doesn't work with PHP sessions using Redis? -joho (03-26-2024, 04:04 PM)joho Wrote:I don't use it because of the lock it applies to sessions via Redis.(03-25-2024, 07:14 AM)ElTomTom Wrote: Today I have the PHP Session with Redis configuration, with fallback, name configuration, etc., all defined in my php.ini file, however in CI4 I cannot use PHP's native session_start() to create my sessions. This is most evident in AJAX requests. At least in CI 3, a page that had about 5 requests took a long time for the page to finish loading all the information, as each page remained locked for 1s. In other words, in total I had 5s loading the data to be able to work. On a large scale, this generates other problems, such as too many connections in the database Imagine you open 5 req, each one opens a database connection. They will remain open for an average of 5 seconds for a page/user. Now you have 10 users, making the same request, there are 50 active requests (10 users x 5 req) in the database that cannot be used by other people. (03-28-2024, 06:57 AM)ElTomTom Wrote:(03-26-2024, 04:04 PM)joho Wrote: Just out of curiosity, because I use PHP session settings geared for Redis too, what is it with CI4 sessions that doesn't work with PHP sessions using Redis?I don't use it because of the lock it applies to sessions via Redis. Ah, yes, I can see where that becomes unbearable. I hadn't thought about that situation. Interesting. -joho
Session without lock has issues on race conditions. If it is not read only session, session data may be lost.
Read https://codeigniter4.github.io/CodeIgnit...oncurrency The current Lock Retry Interval in CI 4.4.6 is 0.1 seconds, not 1 second. And in 4.5.0, you will be able to configure: https://github.com/codeigniter4/CodeIgni...d2f5f4R113 (03-28-2024, 03:27 PM)kenjis Wrote: Session without lock has issues on race conditions. If it is not read only session, session data may be lost. Just to confirm. If I define a Redis or Memcached session in CI 4. php.ini will be completely ignored and whatever is in my session file will be applied, correct?
@ElTomTom Strictly speaking, no.
But the all settings in CI4's Session config file are applied. So it seems you don't need to worry about Session settings if you set in CI4's Session config file correctly. But there are so many settings: https://www.php.net/manual/en/session.configuration.php and CI4 Session does not touch some settings at all. That is the settings are applied. |
Welcome Guest, Not a member yet? Register Sign In |