Home » Php » php – MySQL Set Session wait_timeout, interactive_timeout not working in Codeigniter

php – MySQL Set Session wait_timeout, interactive_timeout not working in Codeigniter

Posted by: admin February 25, 2020 Leave a comment

Questions:

I’m improving a web app done in Codeigniter to control how many people can save a row concurrently.

Since Codeigniter doesn’t include the usual ‘For Update’ or ‘Lock In Share Mode’ functionalities, I’ve done a number of custom queries and have For Update.

The issue is that the rows are locked, but only for a short period of time (10 seconds) even though I’ve set the session to a longer wait timeout, I’ve even set global wait timeouts and the transaction still is killed within 10-15 seconds.

If I implement a sleep function to test, the rows lock properly for however long I set the transaction to sleep for.

If I use MySQL Workbench, the wait timeout works as intended.

    $this->db->query('SET SESSION autocommit = 0');
    $this->db->query('SET SESSION TRANSACTION ISOLATION LEVEL SERIALIZABLE');
    $this->db->query('SET SESSION innodb_lock_wait_timeout = 1');
    $this->db->query('SET SESSION interactive_timeout = 28000');
    $this->db->query('SET SESSION wait_timeout = 28000');
    $this->db->trans_start();

    $query = //Query is here

    $data = $this->db->query("{$sql} FOR UPDATE;")->row();

    return $data;
How to&Answers: