Page 1 of 1

How to ping server from PHP ?

Posted: Wed May 23, 2007 5:14 am
by nils1
Hi,
I am new to PHP.

Can anyone has idea about how to write code to ping the web/application server from PHP?.

If server is down then we should able to send an email.

I want this utility for web sites tracking.

Please help me suggest me any code.

Thanks,
Nil.

Posted: Wed May 23, 2007 6:13 am
by volka
You can let php perform a http request on that server.
E.g. for php versions >= 5.1.0

Code: Select all

stream_context_get_default(array('http' =>array('method' => 'HEAD')));
print_r(get_headers('http://serv.er/'));