Cron to check if the Particular Service is running or not (PHP or Shell)

view story

http://serverfault.com – I am in Centos 6.0 (Linux) with a dedicated server.. I have service called openfire (this could be even mysql as a example) which i want to check periodically to see if its up or not, if not up, i just need to restart the server, I know i can do the restart via shutdown command in the shell or system() using php script. I think this all can be done via SHell script, however since i am web developer i think i can do this via a php script even ? (as far as i am concern) and set a cron job to execute it every 30 min or so. Is this possible, ? if so What is the best way to do this, how do i d (HowTos)