0

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->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->fields[$alias_candidate])) {
      $alias_candidate = $alias . '_' . $count++;
    }
    $alias = $alias_candidate;

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

    return $alias;
  }

Exactly 1309 is: 'table' => $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?

1
  • 1
    Does it consistently fail in the same place. Most likely a lot of things is going on and it end up failing in a random place. To really know what's going on, you should use something like XHPROF, new relic etc to give you a traceback, with information on where time spent which should help you track down the root cause, as my gut tells me you are looking at the symptom right not and not the real issue.
    – googletorp
    May 30, 2017 at 9:44

1 Answer 1

1

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);
2
  • Thanks. I did that on php.ini file for the cli, without luck. I didnt' try to put it inside the function with ini_set. I'll try that.
    – Raf A.
    May 23, 2017 at 11:35
  • 1
    I tried adding the ini_set command in php and it worked. But unfortunately I don't have an answer to WHY a simple SELECT command takes more than 120 seconds, it doesn't make sense. It's like I only fixed the symptom, but not the root cause.
    – Raf A.
    May 30, 2017 at 8:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.