Implementation of spimi algorithm in php