How to ping server from PHP ?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
nils1
Forum Newbie
Posts: 1
Joined: Wed May 23, 2007 5:11 am

How to ping server from PHP ?

Post 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.
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post 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/'));
Post Reply