PHP isn't really a real time system. What you can do however is write your code inside a loop and have it loop continually with a 1 second sleep (so it doesn't lock the CPU and freeze the machine).
Within that loop you can do whatever you want. Just be sure to have some way of stopping it.
My helpful sig has gone because a mod below the administrator gave me an infraction - despite the administrator personally agreeing to it.
If you need any php tips or tricks you can PM me.