rewrite HGStat using PHP