If you are checking for example an IRC server, you can use fsockopen to check if you can connect to the IRC port of that server.
This will report "connection timedout" or "connection refused" if the server is not available.
Otherwise on unix you can execute a ping
ping -c2 www.site.bla and parse the output to see if it worked.