PDA

View Full Version : Check a web site is responding


Sayonara
01-21-2005, 09:18 AM
Hello all.

I want to be able to check a remote site exists and is responding to requests.

I know about gethostbyname() - that checks the DNS records rather than the remote server. What I need is some sort of ping function, but beyond a vague idea that sockets might be involved I'm not sure how to do it.

Any pointers would be great :thumbsup:

cfc
01-21-2005, 01:10 PM
If you're running PHP5, you could use the get_headers (http://ca3.php.net/manual/en/function.get-headers.php) function.

If you're running PHP3, PHP4, or you're running PHP5 and don't want to use experimental functions fsockopen(string hostname, int port [, int &errno [, string &errstr [, float timeout]]] )) (http://www.php.net/fsockopen) could be useful, and use fclose() to close the socket when you're done with it.

If it can't connect it returns false, and if it can connect it returns a resource handle.

Sayonara
01-21-2005, 03:13 PM
I found exactly what I was looking for in the examples for fsockopen().

Thanks :thumbsup: