Well, if there's no response then PHP will sit there waiting, waiting, waiting, ... until it gives up. Use set_socket_timeout() to adjust how patient it will be (don't forget to take into account the time limit the whole PHP script has to run under).
Needless to say; this is a slow job and not one you want to do every time you display the page. I'd recommend storing this connection quality info along with the links themselves, and updating it with a script like this on a regular basis.