在codeigniter类上设置MAX_EXECUTION_TIME不起作用

时间:2019-06-14 11:13:01

标签: php codeigniter

将指令ini_set('MAX_EXECUTION_TIME', '-1')放在脚本顶部或时间贪婪函数的顶部(如下面的代码中)似乎无效,并且我总是会遇到以下错误:< / p>

  

致命错误:超过了300秒的最长执行时间

说明应放在哪里?

public function generate_no_pass_link()
{
    ini_set('MAX_EXECUTION_TIME', '-1');
    $encoder = $this->di->find('ssl_cipher');
    $storage = $this->di->find('storage');
    $salt = $storage->executeSQL("select text from translations where entity='Salt'", \PDO::FETCH_ASSOC)[0]['text'];

    $url = 'https://mydomain/usuario/actualizar_datos/';
    $sql = "select id from clients where state=512 and created_at between  1514764801 and 1559347199";
    $result = $storage->executeSQL($sql);

    try{
        foreach($result as $id){
            $client = $storage->findOneBy('Client',array('id'=>$id));
            $link = $url . urlencode($encoder->encode($client->getEmail(), $salt));
            $client->setLogin_link($link);
            $storage->persist($client);
            $storage->flush();
        }
    }catch(Exception $e){
        echo $e->getMessage();
    }
    echo "Links generados con éxito";
}

1 个答案:

答案 0 :(得分:0)

您应该将其放置在任何位置,但是如果将其放在下面可能需要一段时间的函数下,那么如果脚本花费很长时间才能到达调用它的位置,则可能会在上面超时。因此,您必须将其放在脚本之上。

<?php ini_set('MAX_EXECUTION_TIME', '-1'); 

public function generate_no_pass_link()
{
  //"Your code going here"
}
?>

或者您可以在服务器上的php.ini文件中更改

/etc/php5/cgi/php.ini
/etc/php5/cli/php.ini
/etc/php5/apache2/php.ini

找到这一行:

max_execution_time = 30 //change it to -1

其默认值因服务器而异。您可以将其更改为-1