If you're using [man]fsockopen[/man], you can add a timeout on the socket connection; HTTP support in [man]fopen[/man] and [man]file_get_contents[/man] also allows adding a timeout to the context used by those functions.
A vague answer, but a vague question.