Drupal Elysia Cron Max execution time error, in select.inc PHP Fatal error: Maximum execution time of 120 seconds exceeded in /var/www/domainname.com/public/includes/database/select.inc on line 1309


I have an elysia cron command that takes perhaps 10-15 minutes, in the night. The script also starts some jobs with beanstalk, so it takes a while to execute.

When it runs automatically at night I get that above error message. It doesnt make sense, because when I run the command from the terminal it works: 

drush elysia-cron run elysia_cron_job_name --verbose --ignore-disable --ignore-running --ignore-time


And on line 1309 in select.inc is this:

public function addField($table_alias, $field, $alias = NULL) {
    // If no alias is specified, first try the field name itself.
    if (empty($alias)) {
      $alias = $field;
    }

    // If that's already in use, try the table name and field name.
    if (!empty($this-&gt;fields[$alias])) {
      $alias = $table_alias . '_' . $field;
    }

    // If that is already used, just add a counter until we find an unused alias.
    $alias_candidate = $alias;
    $count = 2;
    while (!empty($this-&gt;fields[$alias_candidate])) {
      $alias_candidate = $alias . '_' . $count++;
    }
    $alias = $alias_candidate;

    $this-&gt;fields[$alias] = array(
      'field' =&gt; $field,
      'table' =&gt; $table_alias,
      'alias' =&gt; $alias,
    );

    return $alias;
  }


Exactly 1309 is: 'table' =&gt; $table_alias,

I've searched the web, and I have no idea where the 120 seconds comes from. I feel like I tried everything. Can someone help?
Please note that Drush can use different PHP configuration file for CLI than your Apache, so you need to increase your time in there (max_execution_time).

To find where is your PHP config file, run: drush status, e.g.

$ drush status
...
 PHP configuration               :  /etc/php/7.0/cli/php.ini                                            
...


then edit the file and increase your max_execution_time to higher value.

Alternatively add the following line in your PHP function which expect to be run by cron for longer time:

ini_set('max_execution_time', 0);