Ping host measured in microseconds

Problem

You want to ping a host on a given port and record time taken in microseconds.

The following solution uses PHP socket libraries to open a connection, to the given host and port – then just close it again. By obtaining the microseconds before and after, it is able to deduce time taken in microseconds.

Additionally I’ve added functionality to print the epoch, so the timestamp can be obtained.