set_time_limit does not work

marvin picture marvin · Feb 27, 2013 · Viewed 19.8k times · Source

I have a bigint class in php, to calculate big numbers. It works well, except the time limit.

I set the time limit with

set_time_limit(900);

in my bigint.php file, and it works in localhost. But in my web host, when I try to calculate 999^999, it yields the error

Fatal error: Maximum execution time of 10 seconds exceeded in /home/vhosts/mysite.com/http/bigint/bigint.php on line 156

This is my code:

public function Multiply_Digit($digit){ //class function of bigint
if($digit==0){$this->str="0";}
else
{
$len=$this->length();
$Result = new bigint("0");
                $carry=0;
                $current;
/*line 156:*/   for ($i = 0; $i < $len; $i++)
                {
                    $current = $this->str[$len-$i-1] * $digit;                    
                    if ($i == 0) { $Result->str = ""+(($current + $carry) % 10); }
                    else{ $Result->str .= ""+(($current + $carry) % 10); }                                        
                    $carry = (($current+$carry) - ($current+$carry)%10)/10;
                }
                $Result->str .= ""+$carry;                
                $Result->str = strrev($Result->str);
                $Result->TrimLeadingZeros();                
                $this->str = $Result->str;//sacma oldu.
                }//else. digit not zero
}//Multiply_Digit()

I tried putting set_time_limit(900); in both starting of php file and the constructor of class, none worked.

I thought it was a session issue, closed my browser and re-opened the page, still it takes 10 seconds as time limit.

What am I doing wrong here?

Answer

Serge Kuharev picture Serge Kuharev · Feb 27, 2013

"This function has no effect when PHP is running in safe mode. There is no workaround other than turning off safe mode or changing the time limit in the php.ini." - http://php.net/manual/en/function.set-time-limit.php

Check it.