doujia1679 2019-01-25 14:58
浏览 192

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.

  • 写回答

1条回答 默认 最新

  • dongnao2048 2019-01-25 15:05
    关注

    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.
    
    评论

报告相同问题?

悬赏问题

  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题