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?
"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.
Probably your apache is configure to stop execution after 10 seconds, does your php.ini have the line:
max_execution_time = 10
if so, to disable the timeout (not recommended) change it to:
max_execution_time = 0
or to any integer limit of your choice:
set_time_limit(360);
You can read more at the php manuals. Generally it's not a good idea to set it to 0 since if for example waiting for a resource that doesn't exists the server process might get stuck.
Update
If the site is hosted than it depends on the hosting company, ask them if it's possible.
another way around it is to use an ajax call instead, to keep the client waiting instead of the server
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With