简体   繁体   中英

Setting MAX_EXECUTION_TIME on codeigniter class doesn't work

Putting the instruction ini_set('MAX_EXECUTION_TIME', '-1') either at the top of the script or at the top of a time greedy function (like in the code down below) doesn't seem to work and I always get the following error:

Fatal error : Maximum execution time of 300 seconds exceeded

Where should the instruction be placed?

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";
}

You should placed it anywhere but if you put it down below on the function that can take a while, then you may get a timeout above if the script takes a long time to get to where you called it. So you have to put it on top of the script.

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

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

Or you can change in the php.ini file on your server

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

find this line:

max_execution_time = 30 //change it to -1

Its by default value vary from server to server. You can change it to -1

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