简体   繁体   中英

CodeIgniter database check for timeout error

I'm running a small webservice that gets data from a user specified database, and some of those queries are heavy and often take longer than usual, because those rows contain base64 images and other needed stuff. When my queries take longer than 30 secs CI crashes somehow. I've tried using $this->db->_error_number() , $this->db->_error_message() and

if ($this->db->trans_status() === FALSE) {
    die('Wops, something weird happened...');
}

But none of them gives me error infos. Anybody knows how to capture those timeout errors and echo them to the user? Thanks.

EDIT:

log output:

...
DEBUG - 2015-04-10 10:34:34 --> Controller "Main" Initialized
DEBUG - 2015-04-10 10:34:34 --> Helper loaded: log_helper
DEBUG - 2015-04-10 10:34:34 --> Database Driver Class Initialized
DEBUG - 2015-04-10 10:35:04 --> Final output sent to browser
DEBUG - 2015-04-10 10:35:04 --> Total execution time: 30.0145
...

Please check mysql.connect_timeout parameter in your phpinfo() and increase in in case require as this may be reason for query timeout.

You can read more about this Here

Your query takes too much time. If your are using webserver(nginx or apache) hey have default timeout. In most cases it 30seconds. You can increase timeout time on your webserver.

Also check php timeout parameters in php.ini max_execution_time Or try to set_time_limit bigger directly in php code. http://php.net/manual/en/function.set-time-limit.php

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM