python implentation of forp written for PHP