Codeigniter数据库会话GET LOCK

I have two webservers running Codeigniter framework and use a load balancer, and I want to store the shared session for both webservers instead of using sticky session from load balancer.

I tried to use ci database session. For few days the connections were excellent, until suddenly it start showing slow query like this:

SELECT GET_LOCK('59e30181bfafeae2d31394d621bab3cc4c401956', 300) AS ci_session_lock;

The query can take from 5 - 15 seconds which slow down the servers.

This is the session configuration in config.php

$config['sess_driver'] = 'database';
$config['sess_cookie_name'] = 'ci_session';
$config['sess_expiration'] = 0; //expire when the browser is closed 
$config['sess_save_path'] = 'ci_sessions';
$config['sess_match_ip'] = FALSE;
$config['sess_time_to_update'] = 300;
$config['sess_regenerate_destroy'] = FALSE;

Does anyone ever experience like this? Thanks before.

If you are facing slow query issue then you need to save your session into files instead of database, this will save your slow and multiple query request.

Example:

$config['sess_driver'] = 'files'; // need to use files

The storage driver to use in CI: files, database, redis, memcached

Then define tmp path:

$config['sess_save_path'] = sys_get_temp_dir();

According to PHP manual, sys_get_temp_dir() Returns directory path used for temporary files

You can also set specific folder to save session in $config['sess_save_path'] as:

$config['sess_save_path'] = 'session_folder'; // this will save session on root inside **session_folder** folder.