我有一个bigint
类在php中,来计算大数字。除时间限制外,它运作良好。set_time_limit不起作用
我设置的时间限制与
set_time_limit(900);
我bigint.php文件
,并在本地主机的工作原理。 但在我的虚拟主机,当我试图计算999^999,它产生的错误
Fatal error: Maximum execution time of 10 seconds exceeded in /home/vhosts/mysite.com/http/bigint/bigint.php on line 156
这是我的代码:
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()
我试图把set_time_limit(900);
在PHP文件的启动以及类的构造函数,没有工作。
我以为这是一个会话问题,关闭我的浏览器并重新打开页面,仍然需要10秒作为时间限制。
我在这里做错了什么?
是不是你的函数写一个非常长的方式'pow($数字,$数字);'? – jeroen 2013-02-27 15:11:05
这只是bigint类中的一个函数。我无法找到一种支持超过20个字符的“数字”的PHP方式。 – marvin 2013-02-27 15:19:38
只是想我会提到它,因为它可能会帮助您优化您的功能; PHP有很多数学函数包括:-) – jeroen 2013-02-27 15:21:56