I'm getting Session: Error while trying to free lock for ci_session show up in the error log a couple times a minute, sometimes, and every 15 minutes other times. Using Redis for sessions. It's not happening on a different server that has almost the same code base and is sharing the same Redis server, albeit with a different session name.

I'm using session_write_close() on every page as soon as I'm done handling sessions.

Re: CodeIgniter redis sessions 80 80

Switched to file-based sessions and it's not happening either.

Re: CodeIgniter redis sessions 80 80

Looks like this has been a problem in PHP for a long time. On a brighter note, it looks like a fix is on the way.

Re: CodeIgniter redis sessions 80 80

Those links appear to be related to native PHP sessions. Codeigniter rolls its own session library that implements locking differently than native PHP does.

Re: CodeIgniter redis sessions 80 80

The bugs I linked to are present in the PHP Redis driver, phpredis.

CodeIgniter's Sessions functionality uses it to connect to Redis. There is even a caveat in the documentation stating

Since Redis doesn’t have a locking mechanism exposed, locks for this driver are emulated by a separate value that is kept for up to 300 seconds.

Re: CodeIgniter redis sessions 80 80

Ah, thanks. I think my problem is I have a race condition with some AJAX. I'm initiating a request before a previous request completes. However, I'm using session_write_close() immediately after retrieving session data when the script first runs, so it should be releasing the lock before doing any heavy lifting.

Re: CodeIgniter redis sessions 80 80

Two years later and I'm still struggling with this.

Re: CodeIgniter redis sessions 80 80

I have same problem, can anybody help me. Performance issue when i am using ajax in Code Ignitor.

Re: CodeIgniter redis sessions 80 80

If you’re having performance issues, use session_write_close() as close as possible to the top of each script. (As soon as you finish using session data)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.19 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.