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.

Recommended Answers

All 8 Replies

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

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

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.

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.

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

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

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 developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.