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?
pow($digit, $digit);
? – Chlortetracycline