CodeIgniter Forums
CI Session - Lost connection to MySQL server during query - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Development (https://forum.codeigniter.com/forum-6.html)
+--- Forum: Issues (https://forum.codeigniter.com/forum-19.html)
+--- Thread: CI Session - Lost connection to MySQL server during query (/thread-72434.html)



CI Session - Lost connection to MySQL server during query - bharatmaher - 12-19-2018

My site is working fine but sometimes it suddenly starts giving CI_SESSION error...

Error is : 


Code:
ERROR -> Query error: Lost connection to MySQL server during query - Invalid query: SELECT `data`
FROM `ci_sessions`
WHERE `id` = '44278e7a05ed07842bgf15b1a5feaff0dcee76c3'

ERROR --> Query error: MySQL server has gone away - Invalid query: INSERT INTO `ci_sessions` (`id`, `ip_address`, `timestamp`, `data`) VALUES ('21440e7a66ed02342bbf15b1a3feaff0dcee76c3', 'xxx.xx.xx.xx', 1545006351, '')

ERROR - --> Query error: MySQL server has gone away - Invalid query: SELECT RELEASE_LOCK('5d966d065ca3606e9cdf23c761035e54') AS ci_session_lock

 Please let me know if anyone has any idea about this...
 
 My config setting is : 

Code:
$config['sess_cookie_name'] = 'ci_session';
$config['sess_expiration'] = 7200;
$config['sess_expire_on_close'] = TRUE;
$config['sess_encrypt_cookie'] = FALSE;
$config['sess_use_database'] = TRUE;
$config['sess_table_name'] = 'ci_sessions';
$config['sess_match_useragent'] = TRUE;
$config['sess_time_to_update'] = 300;
$config['sess_driver'] = 'database';



RE: CI Session - Lost connection to MySQL server during query - php_rocs - 12-19-2018

@bharatmaher,

In your config database settings file, what do you have ['pconnect'] set to?


RE: CI Session - Lost connection to MySQL server during query - Pertti - 12-20-2018

Some time ago we noticed issues with sessions as well when using database storage. This has been discussed few times on this forum why it has to work the way it does, but we ended up changing to file based session storage while we were moving to Redis. Had no session issues since, but last 18 months we never managed to move to Redis due to reason completely unrelated to CodeIgniter :|


RE: CI Session - Lost connection to MySQL server during query - skunkbad - 12-20-2018

This isn't a CodeIgniter issue. Same errors can be seen in your logs with any framework. This is a problem with the server. I know this because I usually modify the error handler so it emails me when there are errors, and I get these errors from multiple accounts/websites, at the same time, and they are not all using CodeIgniter. Unless you are in control of the server, or your host can provide more information, it's unlikely there's anything you can do about it.


RE: CI Session - Lost connection to MySQL server during query - bharatmaher - 12-26-2018

(12-19-2018, 09:18 AM)php_rocs Wrote: @bharatmaher,

In your config database settings file, what do you have ['pconnect'] set to?

@php_rocs,
 
 Thanks for your update!.

  My ['pconnect'] is set to FALSE.
 
  Thank you.


RE: CI Session - Lost connection to MySQL server during query - bharatmaher - 12-26-2018

(12-20-2018, 08:08 AM)skunkbad Wrote: This isn't a CodeIgniter issue. Same errors can be seen in your logs with any framework. This is a problem with the server. I know this because I usually modify the error handler so it emails me when there are errors, and I get these errors from multiple accounts/websites, at the same time, and they are not all using CodeIgniter. Unless you are in control of the server, or your host can provide more information, it's unlikely there's anything you can do about it.

 @skunkbad,

 Thank you for your response.

  I'll definitely discuss with my server administrator.  The error is frustrating for us because it completely makes my site down for 4-5 minute and we ended up with losing some important websites customers.


RE: CI Session - Lost connection to MySQL server during query - InsiteFX - 12-27-2018

You can also try this.

PHP Code:
$this->db->reconnect(); 



RE: CI Session - Lost connection to MySQL server during query - bharatmaher - 01-02-2019

(12-27-2018, 03:59 AM)InsiteFX Wrote: You can also try this.

PHP Code:
$this->db->reconnect(); 

  @InsiteFX,

   Where I can add above line?


RE: CI Session - Lost connection to MySQL server during query - InsiteFX - 01-19-2019

I would run it when you do your queries or in your model constructor.