CodeIgniter Forums
Session: Error while trying to free lock for ci_session - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Development (https://forum.codeigniter.com/forumdisplay.php?fid=6)
+--- Forum: Issues (https://forum.codeigniter.com/forumdisplay.php?fid=19)
+--- Thread: Session: Error while trying to free lock for ci_session (/showthread.php?tid=65249)

Pages: 1 2 3 4 5 6


Session: Error while trying to free lock for ci_session - jcarpenter - 05-19-2016

I have reviewed the other few posts related to this error:

Session: Error while trying to free lock for ci_session

and cannot figure out the problem. Our site isn't even close to taking 5 seconds for page loads, in fact they are typically 500ms. Therefore, any other ideas on how to troubleshoot?

As a followup to this I configured memcached (the session driver we are using) to NOT use file locking. I confirmed this with a phpinfo page. Even after turning off file locking I still get this message.


RE: Session: Error while trying to free lock for ci_session - Narf - 05-20-2016

Changing php.ini settings won't change anything.
Which CI version are you using? If it's not the latest, upgrade to it.


RE: Session: Error while trying to free lock for ci_session - jcarpenter - 05-20-2016

(05-20-2016, 02:06 AM)Narf Wrote: Changing php.ini settings won't change anything.
Which CI version are you using? If it's not the latest, upgrade to it.

We are on the latest version, 3.0.6


RE: Session: Error while trying to free lock for ci_session - consigliere - 05-20-2016

I have the same issue.
Our site is hosted on AWS and we have ELB with 5 servers behind.
Yesterday we upgraded CI on 3.0.6 version.
We are using memcached for handling sessions.
In php.ini session handler is setup for memcached .
When I try to use CI with memcached site is loading forever.
But when I setup CI for using files the site is loading normally but have some weird issues.
For example on one page is fine but when I click on the other I have been logout or even use some previous users which I was logged in.
What should I do to make this work as it is supposed to work.
Thanks


RE: Session: Error while trying to free lock for ci_session - consigliere - 05-24-2016

Someone?


RE: Session: Error while trying to free lock for ci_session - spjonez - 05-24-2016

I have the same issue with the Redis driver and am also using CI 3.06 on AWS Elastic Beanstalk: http://forum.codeigniter.com/thread-64854.html

Session library is autoloaded and I am calling session_write_close where applicable.


RE: Session: Error while trying to free lock for ci_session - consigliere - 05-24-2016

@spojoneze,

maybe someone will eventually provide solution or creators will make this work in next version(s).
This is ridiculous, response time with memcached is 5s - 6s, when move to files (php.ini session handler memcached) response is 100ms..
But with files it just logout users from time to time, sometimes in 10 minutes sometimes after 3 clicks on site...
In CI 2 it worked like a charm with same server configuration.. It is really annoying


RE: Session: Error while trying to free lock for ci_session - spjonez - 05-24-2016

Are you calling session_write_close after you're finished writing session data? It won't fix the error but it will speed pages up considerably.


RE: Session: Error while trying to free lock for ci_session - consigliere - 05-24-2016

Thanks spjonez,

but I don get it, where to call session_write_close() ?
For example I am having this in MY_Controller in __construct:

PHP Code:
if(isset($this->session->userdata["user_id"])){
    
$data["userdata"] = $this->session->userdata;
        if (
$this->config->item($this->uri->segment(1), "lang_list") !== NULL){
            
$this->current_lang $this->uri->segment(1);
        }
    else{
        
$this->current_lang $this->session->userdata["lang"];
    }

Also I am having some other checks in session or update session variable like this:

PHP Code:
if (isset($this->session->userdata["notifications"]["budget"])) {
    
$notifacations $this->session->userdata["notifications"];
    
$notifacations["budget"] = true;
    
$this->session->set_userdata("notifications"$notifacations);

Where I should put session_write_close() ?
Also my app is heavily depends on AJAX calls.
I tried in __desctruct function of MY_Controller to add session_write_close() but with no success.
Beside this I have on numerous places in app where I do echo like this:
 
PHP Code:
<?php echo $this->session->userdata["lang"];?>
Should I after every operations with sessions to call session_write_close() function?


RE: Session: Error while trying to free lock for ci_session - spjonez - 05-24-2016

In any controller method after you're finished writing session data. You can still get session data after you've called session_write_close but you can't modify it.

Code:
<?php if ( !defined( 'BASEPATH' ) ) exit( 'No direct script access allowed' );

class Welcome extends CI_Controller {
    public function index( ) {

        // code that modifies session data

        session_write_close( );

        $this->load->view( 'welcome_message' );
    }
}