you don't have to do this yourself. there already is a built-in sleep feature. -> ph_setautodisable()