You can do it in 3 ways:
1) Call pcntl_fork in PHP and check the timeout in parent process. Kill it if it exceeds using linux kill command.
2) Include timeout in a bash script that you will invoke using shell_exec, see this example: http://www.bashcookbook.com/bashinfo/source/bash-4.0/examples/scripts/timeout3
3) Use proc_open / proc_terminate functions
Personally I would go with number 3, it's the cleanest. If you need quick and dirty, use number 2.