Well here are a couple of π generators I put together. Both have the advantage that they can produce digits while they're running, instead of you having to wait until the end. There are two because there are advantages and disadvantages to them.
The first one starts out slow but speeds up as it proceeds; it also needs the number of digits required to be specified in advance (so that it can allocate space for them). The supplied code sez 2400 digits.
The second could probably do with some more optimisation; it's not exactly fast, but it will keep cranking out digit after digit for as long as you're prepared to put up with it (or it needs to be upgraded so that lfts() uses bc arithmetic to generate the next array!).
NOTE: I'm not 100% certain these are correct. recommend you check against an existing expansion (which, if that's all your after, would proably be a better solution anyway!).
Even better might be a native executable to calculate the digits, and call it from the command line (something from http://home.istar.ca/~lyster/pi.html perhaps).
$size = 4*2400;
$e = 0;
$f = array_fill(0, $size, 2000);
for($c=$size-1; $c>=0; $c-=14)
{
$d = 0;
for($b=$c; $b>0; --$b)
{
$g = 2*$b-1;
$d = $d*$b+$f[$b]*10000;
$f[$b] = $d%$g;
$d = intval($d/$g);
}
printf('%04u',($e+$d/10000));
$e = $d%10000;
}
function extr($qrt,$x)
{
return bcdiv(bcadd(bcmul($q,$x),$r),$t);
}
function gcd($a,$b)
{
if($a[0]=='-') $a = substr($a,1);
if($b[0]=='-') $b = substr($b,1);
while(bccomp($b,0))
{
$nb = bcmod($a,$b);
$a = $b;
$b = $nb;
}
return $a;
}
function comp($qrt, $uvx)
{
static $rescale=0;
list($q,$r,$t) = $qrt;
list($u,$v,$x) = $uvx;
$a = bcmul($q,$u);
$b = bcadd(bcmul($q,$v),bcmul($r,$x));
$d = bcmul($t,$x);
if($rescale==10)
{
$gcd = gcd(gcd($a,$b),$d);
if($gcd!=1)
{
$a = bcdiv($a,$gcd);
$b = bcdiv($b,$gcd);
$d = bcdiv($d,$gcd);
}
$rescale = 0;
}
else
{
$rescale++;
}
return array($a,$b,$d);
}
function lfts()
{
static $k=1;
$return = array($k, 4*$k+2, 2*$k+1);
$k++;
return $return;
}
function do_pi()
{
$z = array(1,0,1);
while(true)
{
$y = intval(extr($z, 3));
if($y==intval(extr($z, 4)))
{
echo $y;
$z = comp(array(10, -10*$y, 1), $z);
}
else
{
$z = comp($z,lfts());
}
}
}
do_pi();