wait() bugs

The time calculations are wrong.  microtime(true) returns the number of seconds as a float where microseconds are expressed as the decimal portion.

Also, switch to usleep() because sleep(0.1) doesn't work as expected, i.e., sleep() expects the number of seconds as an integer.