3
votes

I am struggling to find where to set the command timeout in Yii for MySql database (some queries are taking a while to run).

In the source code the file protected/config/main.php has these settings:

'db'=>array( 'connectionString' => 'mysql:host=xxx;dbname=xxx;port=xxx;timeout=100;', 'emulatePrepare' => true, 'username' => 'xxx', 'password' => 'xxx', 'charset' => 'utf8', 'schemaCachingDuration'=>3600, ),

The timeout seems to apply to connections, and command timeout default is 30 seconds (that's the one I need to increase).

Web pages fetching from db usually fail with Fatal error: Maximum execution time of 30 seconds exceeded in \YiiRoot\framework\db\CDbCommand.php on line 508.

line 508 is

$this->_statement->execute();

so obviously is a query timeout.

1

1 Answers

3
votes

This is not a mysql error, it is a php error. Fatal error: Maximum execution time of 30 seconds is set by the php.ini setting max_execution_time the default is 30. You can either change your php.ini file, or you can adjust it with .htaccess or on the individual function you can use the set_time_limit() command.

http://www.php.net//manual/en/function.set-time-limit.php