Use System PHP library for the which command