optimize code for PHP