Initial porting bash script in php script