Tohle je v Jave, pomerne zjednoduseny algoritmus - do PHP si to musis prepsat sam
Kód:
public class VypocetPi {
   static final double c_presnost = 1E-7;
   

   public static void main(String[] args) {

   double currPi = 0;
   double i = 1;
   int counter = 0;
   long xbegin, xend;

      xbegin = System.currentTimeMillis();

      do {
         currPi += 4/i - 4/(i+2);
         i+=4;
         counter++;
      } while (Math.abs(Math.PI - currPi) > c_presnost);

      xend = System.currentTimeMillis();

      
   System.out.println("Vypocteno Pi = " + currPi + 
                         " v case: " + (xend - xbegin) + " ms.");
   System.out.println("Math.PI =      "+Math.PI);
   System.out.println("Pocet pruchodu: " + counter);
   System.out.println("Presnost vypoctu: " + c_presnost);                                              
   }
}