1

I have problem with a sleeping queries. Some tasks in my WEB tooks longer than 1min so mysql queries gets status "sleeping" until proccess will be closed. I want to close proccess just after grabbing details.

$delay = $this->db->select('*');
    $delay = $this->db->get('system_status');
    if($delay->num_rows() != 0) $delay = $delay->result_array();

and after this code should be some clear or something to delete inserted row to process list until it will be declared as "sleeping". Any ideas?

1 Answers1

1

As I noted in the comments, You need to renew the database connection after the 1min timeout.

CodeIgniter has a method to reconnect the database connection:

$this->db->reconnect();

From the Doc:

Reconnecting / Keeping the Connection Alive

If the database server's idle timeout is exceeded while you're doing some heavy PHP lifting (processing an image, for instance), you should consider pinging the server by using the reconnect() method before sending further queries, which can gracefully keep the connection alive or re-establish it.

Hashem Qolami
  • 97,268
  • 26
  • 150
  • 164
  • Thanks, but like as I said, I do not need to renew all connection, I just need to delete last query inserted into proccess list until it get status "sleeping" – Žydrius Nežydras Feb 10 '14 at 11:12
  • @ŽydriusNežydras To reset the old queries, you might want to check this topic on SO: http://stackoverflow.com/questions/6246023/how-to-reset-codeigniter-active-record-for-consecutive-queries – Hashem Qolami Feb 10 '14 at 11:17
  • yes, this is something I want. But there is info how to kill all sleeping proccessess, how do I delete last one inserted? – Žydrius Nežydras Feb 10 '14 at 11:19
  • @ŽydriusNežydras It needs to get hands dirty to hack the core files :), I'll give it a try in next 30mins. – Hashem Qolami Feb 10 '14 at 11:21
  • do not push yourself if don't have time. I tried to add `$this->db->start_cache();` and `$this->db->stop_cache();` `$this->db->flush_cache();` after every query in my controller and I think it works. – Žydrius Nežydras Feb 10 '14 at 11:26
  • @ŽydriusNežydras In `system/database/DB_active_rec.php` **[Lines #L1995-L2042](https://github.com/EllisLab/CodeIgniter/blob/2.1-stable/system/database/DB_active_rec.php#L1995-L2042)**, there are two reset function for `select` and `write`, which use `_reset_run()` method to reset the variables. But these methods are `protected`, you could extend the class to create your public methods, or simply change the core file. – Hashem Qolami Feb 10 '14 at 11:50